I am trying to get the selected checkboxes value and the hidden field value next to it when user submits the 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 it will gives me all the checkbox value even thought they were not checked. Any one could help me about this? Thanks a lot!
First of all, you’re using the exact same name for your input elements. You should do something like:
To select all inputs which are checked, use: