I know the question title may be confusing, but here is what I am trying to achieve:
I have a UL within a table filled with many items. One of the cells of the list contains a checkbox. Those checkboxes are all named in an array “itemsDone[]” I have a button in a side menu (outside of a form). I would like this button to send a query to my server to update a value for each checkbox that is checked… is it possible? I’ve been Googling for roughly an hour, and I may be seeking the wrong keywords… I would appreciate any help given.
Thank you guys and have a nice day!
Edit: There are no forms at all inside the PHP page.
Edit2: Here is the code I now have:
<script type="text/javascript">
$(document).ready(function(){
$("#saveCheckboxes").click(function(){
var check = Array();
var counter= 0;
$('.itemsDone').each(function(){
if(this.checked)
{
check[counter] = this.value;
counter+=1;
console.log(check[counter]);
}
})
$.post('setCommandes.php',{'check[]':check}, function(data) {
alert(data);
});
return false;
});
});
</script>
Here is my setCommandes.php content:
<?php
include('includes/connexion.php');
$data = $_POST['check[]'];
$db_select=mssql_select_db("Test_CommandesWeb");
foreach ($data as $checks)
{
$sql = "UPDATE Commandes SET CommandeFaite='1' WHERE CommandeId='$checks'";
mssql_query($sql,$connexion);
}
?>
I am getting an error (Invalid argument supplied) on my foreach statement at the moment.
You should be able to do this using jQuery.post()
I’m not sure about what your page looks like but I guess the code would be something like this:
//make sure to use the a proper selector