jquery - Retrieving values of checked checkboxes -


i have table (below) containing value associated checkbox.

<table id="testtable"> <tbody>     <tr id="tr1">         <td><input type="checkbox" value="value1"></td>         <td>row 1</td>         <td>a</td>     </tr>         <tr id="tr2">         <td><input type="checkbox" value="value2" ></td>         <td>row 2</td>         <td>b</td>     </tr>         <tr id="tr3">         <td><input type="checkbox" value="value3"></td>         <td>row 3</td>         <td>c</td>       </tr>     </tbody> 

once user has selected combination of checkboxes, need determine values associated checkbox has been checked (after user clicks on 'finished' button).

this have far

$('#finished').click(function() {   $('#testtable tr').filter(':has(:checkbox:checked)').each(function() {      $tr = $(this);     $('td', $tr).each(function() {          // need bit      });   }); }); 

i having difficulty getting values of checkboxes user has selected.

just select selected checkboxes , collect values:

var values = []; $("input[type='checkbox']:checked").each(function () {      values.push({"val": $(this).val(), "tr": $(this).closest("tr").attr("id")}); }); 

this generate array this:

[    {        "val": "value1",        "tr":  "tr1"    },    ... ] 

...containing checked checkboxes, sure.

jsfiddle


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -