View Full Version : Checkbox array with PHP and Ajax

05-05-2009, 02:01 PM
Hi All.

Please bear with me. I have table rows that generate on my page, from a database. New row for each record etc. At the end of each row I have a checkbox which I use to allow the user to select that item. In PHP it works fine with the following code:

$selected = $_POST['chkSelect'];

foreach($selected as $k => $id_selected)
//... Update database using ID's selected
<input name="chkSelect[]" type="checkbox" id="chkSelect" value="<?php echo $rows['id']; ?>" />
However, I need to change this method to use Ajax calls so I can easily validate items first. Instead of the code above I do the following:

// ... Ajax object setup code...
document.getElementById("ajaxResponse").innerHTML = ajaxRequest.responseText;

var selected = document.getElementById('chkSelect').value;

var queryString = "?selected="+selected;

// Specify URL of server side php script
ajaxRequest.open("GET", "content.php"+ queryString, true);
Then inside the content.php page I use the same PHP code as described in the first method.

This works great for first checkbox selected but I can't get the Ajax request to send the checkbox array so the PHP script recieves all the ID's selected.

Any help is much appreciated.

09-01-2010, 07:26 AM
hey, i m havin exactly the same problem as u've.
did u solve it?