jQuery val() undefined
- by betacar
We have the following XHTML table:
<tr class="encabezado">
<th scope="col" width="2%">1</th>
<th scope="col" width="2%">2</th>
<th scope="col" width="2%">3</th>
<th scope="col" width="2%">4</th>
<th scope="col" width="2%">5</th>
<th scope="col" width="2%">...</th>
<th scope="col" width="2%">31</th>
</tr>
<tr>
<th scope="row">Area 1<input name="line_config" type="hidden" value="0,5,50" /></th>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt">...</td>
<td class="gantt"> </td>
</tr>
<tr>
<th scope="row">Area 2 <input name="line_config" type="hidden" value="0,0,10" /></th>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt"> </td>
<td class="gantt">...</td>
<td class="gantt"> </td>
</tr>
When there is a click over a TD.gantt element, we want jQuery to get the value from input[name='line_config'] tag. We try the following jQuery code, but val() returned 'undefined':
$(document).ready(function() {
function sum_day(tag, status, column) {
var total_day = 0;
var index_pos = 0;
var values = 0;
values = tag.closest('tr').children("input[name='line_config']").val();
alert(values); //Return undefined
return total_day;
}
$('td.gantt').click(function() {
var gantt_tag = $('td.preop');
$(this).toggleClass('preop');
sum_day(gantt_tag, 'preop', $(this).index());
});
});
Are we getting right the value way? If anyone can help us, we appreciate... =)