I am trying to get the value of a checkbox inside a PHP do while loop, passing the selected item value into a process page (get-mod.php) i am using below code but my console returns [object NodeList] any suggestions will help.
My PHP do while loop.
$i = 1;
do{
echo '<input type="checkbox" name="checkboxG[]" id="checkboxG'.$i.'" class="css-checkbox" checked="checked" value="'.$row['modelID'].'" /><label for="checkboxG'.$i.'" class="css-label">'.summary($row['model']).'</label><br/>' ;
$i++;
}while($row = mysql_fetch_assoc($c));
My ajax code.
$(document).on('change','.css-checkbox',function(){
var list = document.getElementsByName('checkboxG[]');
console.log("Getting data for "+list);
$.ajax({
type: 'POST',
url:'get-mod.php',
data:'getID='+list,
success:function(html){
$('#result1').html(html);
}
});
});
I am trying to pass the result inside a div with a id of result1, here is my php code (get-mod.php), but for now i just want to return the values of selected checkboxes.
$r = $_POST['getID'];
print_r($r);
$(this)to get the checkbox that they changed. And don't you need to distinguish whether the box is checked or unchecked?whileloop, not ado-whileloop, because you need to fetch the row before you put the value into the checkbox.$("form-id").serialize().That's all