javascript - How to get the selected checkbox value? -


i trying selected checkboxes value , hidden field value next when user submits form.

<form....>  <td><input type='checkbox' name='checkbox' value='1' ></input></td> <input type='hidden' name='sid1' value='1'/>  <td><input type='checkbox' name='checkbox' value='1' ></input></td> <input type='hidden' name='sid2' value='2'/>  <td><input type='checkbox' name='checkbox' value='1' ></input></td> <input type='hidden' name='sid3' value='3'/> 

i try:

$(document).ready(function(){     if( $("input[name='checkbox']['checked']")) {         $("input[name='checkbox']['checked']").each(function(){              var test=$(this).val();             alert(test);             })     } }) 

but gives me checkbox value thought not checked. 1 me this? lot!

first of all, you're using exact same name input elements. should like:

<input type='checkbox' name='checkbox[]' value='1'/> <input type='checkbox' name='checkbox[]' value='2'/> <input type='checkbox' name='checkbox[]' value='3'/> 

to select inputs checked, use:

$('input:checked').each(function() {    // pass value nearby hidden input    $(this).parent('td').next('input').val(this.value); }); 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -