Good evening guys,
I'm trying to pass multiple checkbox values through AJAX and process them with a external .php script. Goal: delete multiple rows using checkboxes without refreshing the page.
Please assist me with passing the selected checkboxes into the datastring and putting them in the mysql command in the external .php file. This is the code so far:
The checkboxes:
<form name="frmMain" id="myForm" method="post" OnSubmit="return onDelete();">
<input class="checkbox_button_del" type="submit" id="buttondel" value="Delete" /> // submit to ajax
<input type="checkbox" class="cb-element" name="chkDel[]" id="chkDel<?=$i;?>" value="' .($id). '">
<input type="hidden" name="hdnCount" value="<?=$i;?>">
</form>
The AJAX:
$(function () {
$(".checkbox_button_del").click(function () {
var id = $(this).attr("id");
var dataString = 'id=' + id; //pass checkbox ids somehow
var parent = $(this).parents('tr:first');
$.ajax({
type: "POST",
url: "core/actions/delete_multiple.php",
data: dataString,
cache: false,
success: function () {
parent.fadeOut('300', function () {
$(this).remove();
});
$("#display").load("display.php")
}
});
return false;
});
});
The delete script:
// receive checkbox ids from ajax and delete rows
for($i=0;$i<count($_POST["chkDel"]);$i++)
{
if($_POST["chkDel"][$i] != "")
{
$strSQL = "DELETE FROM players ";
$strSQL .="WHERE id = '".$_POST["chkDel"][$i]."' ";
$objQuery = mysql_query($strSQL);
}
}