javascript - Format And join values of a table row cells -
i join table row cell values , format joined values format
lamivudine 98% (rsd = 1.3% ; n= 6)
and if next checkbox in next row clicked new value should
lamivudine 98% (rsd = 1.3% ; n= 6) : zidovudine 95% (rsd = 1.9% ; n= 9)
and on , forth....
here table rows
<tr class="assay_row"> <td>lamivudine</td> <td>98%</td> <td>1.3%</td> <td>6</td> <td><input type="checkbox" name="case[]" class="case" /></td> </tr> <tr class="assay_row"> <td>zidovudine</td> <td>95%</td> <td>1.9%</td> <td>6</td> <td><input type="checkbox" name="case[]" class="case" /></td> </tr> <tr class="assay_row"> <td>zidovudine</td> <td>1.5922307662924</td> <td>1.3636240087592</td> <td>9</td> <td><input type="checkbox" name="case[]" class="case" /></td> </tr>
my js far
$(document).ready(function() { $("input.case").click(myfunc); }); function myfunc(ele) { var values = new array(); $.each($("input[name='case[]']:checked").closest("td").siblings("td"), function () { values.push($(this).text()); }); alert("val---" + values.join (", ")); }
suggestions
you should looping on tr
elements, not td
elements. within each row, need concatenate td
contents format want.
function myfunc(ele) { var values = [] $("input[name='case[]']:checked").closest("tr").each(function () { var tds = $(this).children(); values.push(tds.eq(0).text() + " " + tds.eq(1).text() + " (rsd = " + tds.eq(2).text() + " ; n = " + tds.eq(3).text() + ")"); }); alert("val---" + values.join (" : ")); }
Comments
Post a Comment