I would like a way to have a confirm box pop up when a user clicks “delete” to remove a record.
Something like:
<script language="JavaScript" type="text/javascript" >
function confirmDelete() {
if(confirm("Would you like to delete the selected products?")) {
<?php
$allCheckBoxId = $_POST['checkbox'];
array_map ('mysql_real_escape_string', $allCheckBoxId);
$ids = implode(",", $allCheckBoxId);
$sql = "DELETE FROM products WHERE `id` IN ($ids)";
mysql_query($sql);
?>
}
}
</script>
With an onclick:
echo "<input type='submit' name='submit' value='Delete' onclick='confirmDelete()' />";
But I know it’s not possible to be using Javascript & PHP together like this. Is there another way to do this? Maybe PHP has its own kind of confirm? Please give any ideas!
Thank you.
It is pretty easy to make use of AJAX for this case. Simply place your PHP in the
scriptDelete.phpfile and make sure you pass the proper arguments and their values in thedataproperty. For this example I just pass an id of 5.Another way would be to post the form back to its own page like:
So you simply post the form back to
yourpage.phpand on top of this page you do something like: