Reputation: 12347
I have this table, from which i'd like to select all the td
elements value if the checkbox is checked
and then put all the elements in some array or string, so that i can transfer it to server side.
<table id="tableDg">
<tbody>
<tr>
<td><input type="checkbox" class = "chkbCsm" ></input></td>
<td width="10%" align="center"> <input type="hidden" id="nameText" readonly="true" value="{name}">{name}</input></td>
<td width="22%" align="center"> <input type="hidden" id="nameText" readonly="true" value="{host}">{host}</input></td>
</tr>
</tbody>
</table>
Here is what i am doing on jquery side, but it does the selecting thing irrespective of the checkbox being on. Please somebody help me get it in some array.
$('#tableDg tbody tr').live('click', function (event) {
$(this).find('td').each( function( index, item ) {
if ( $(this).has(':hidden') ) {
alert( $(this).find(':hidden').val() );
}
});
});
Added a jsFiddle link
Take a look here
Upvotes: 0
Views: 362
Reputation: 22395
$('#tableDg tbody tr').live('click', function (event) {
if ($('input.chkbCsm', this).is(':checked'))
{
$('input:hidden', this).each(function() {
alert(this.value);
});
}
});
Upvotes: 1
Reputation: 14380
You're not checking if checkbox is checked or not in your code.
if($(".chkbCsm:checkbox").is(":checked")
{
$(this).find('td').each( function( index, item ) {
if ( $(this).has(':hidden') ) {
alert( $(this).find(':hidden').val() );
}
});
}
Upvotes: 0