KaoriYui KaoriYui - 2 years ago 32
PHP Question

Passing a value from a checkbox with multiple values using ajax

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;


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/>' ;


}while($row = mysql_fetch_assoc($c));

My ajax code.


var list = document.getElementsByName('checkboxG[]');
console.log("Getting data for "+list);

type: 'POST',



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'];


Answer Source

You can try this solution.

var data = { 'getID[]' : []};
$("input:checked").each(function() {

And also


Then print $_POST in PHP file you get all selected data.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download