We have the following form:
<form>
...
<table width="100%" cellspacing="0" class="datagrid_ppal">
<tbody>
<tr>
<th scope="row">Area 1 <input name="config_line" type="hidden" value="0,5,50" /></th>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
...
</tr>
</tbody>
</table width="100%" cellspacing="0" class="datagrid_ppal">
...
<form>
What we need is to get the first, second or third from the hidden input value. We have tried this and didn't work:
var value = $('th').children('input:hidden').val();
Can anyone help us? We would really appreciate it.
asked Jun 1, 2010 at 14:32
betacar
4362 gold badges9 silver badges22 bronze badges
3 Answers 3
The value of your hidden field is not an array, but just the string: "0,5,50".
To retrieve that value using jQuery use:
$('input[name=config_line]').val()
To split that string into an array use the split() method.
Combined:
var firstValue = $('input[name=config_line]').val().split(",")[0]; // etc...
answered Jun 1, 2010 at 14:36
Koen
3,6912 gold badges37 silver badges58 bronze badges
var value = $('input[name=config_line]').val();
var valueArry = value.split(',');
var v1 = valueArry[0];
var v2 = valueArry[1];
var v3 = valueArry[2];
Comments
answered Jun 1, 2010 at 14:47
DMin
10.5k10 gold badges50 silver badges66 bronze badges
Comments
lang-js
$('th')is selecting all thethelements on the page. Are there others?.val()will return the value of the firstthit finds on the page.