saminathan saminathan - 1 year ago 164
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>
<tr role="row" class="even">
<td class=""><input type="checkbox" value="12"></td>
<td class="sorting_1">Airi Satou1</td>
<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.

$('.example tr input[type="checkbox"]:checked').each(function(){
var chk_len = $('.example input[type="checkbox"]:checked').length;
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();
var abc = $('.example tr td:eq('+i+')').html();

Please help me on this. Thanks in advance.

Answer Source

it should be much simpler than that

    $('.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();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download