saminathan saminathan - 4 months ago 23
HTML Question

how to get td values row by row if the checkbox is checked

I tried to get the td values row by row if the checkbox is checked. Below is my HTML table format.

<table class="example">
<tr role="row" class="odd ">
<td class=""><input type="checkbox" value="12"></td>
<td class="sorting_1">Airi Satou</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>33</td>
<td>$162,700</td>
</tr>
<tr role="row" class="even">
<td class=""><input type="checkbox" value="12"></td>
<td class="sorting_1">Airi Satou1</td>
<td>Accountan1t</td>
<td>Tokyo1</td>
<td>331</td>
<td>$162,7001</td>
</tr>
</table>
<input type="submit" class="tble_submit">


Based on the selection of checkboxes i need the td values. If i checked both then i need both tr td. I tried with below jquery code which always returning the first tr td values even if i checked both checkboxes.

$(".tble_submit").click(function(){
$('.example tr input[type="checkbox"]:checked').each(function(){
var chk_len = $('.example input[type="checkbox"]:checked').length;
for(i=0;i<=chk_len;i++){
if ($('.example tr:eq('+i+') td input[type="checkbox"]:checked')){
var $row = $(this).parents('tr');
var table_len = $('.example tr:eq('+i+') td').length;
var ab = $('.example tr td:eq('+i+') input').val();
alert(ab)
for(i=1;i<table_len;i++){
var abc = $('.example tr td:eq('+i+')').html();
alert(abc)
}
}
}
});
});


Please help me on this. Thanks in advance.

Answer

it should be much simpler than that

$(".tble_submit").click(function(){
    $('.example tr input[type="checkbox"]:checked').each(function(){
      var $row = $(this).closest('tr');
      $('td:not(:first-child)', $row).each(function(i){
          var abc = $(this).text();
          alert(abc);
      })
    });              
});