I have a table that in front of every row there is a checkbox, if any rows are checked and delete submit button is clicked, checked rows will be deleted. I'm trying to make a confirmation from the user before the delete action, but I couldn't make it work.
Here is what I did:
I put a JavaScript function Submit()in the form:
<form action="Posting.php" method="post" onclick=Submit(); >
....
<input type="submit" name="submit_del" value="Delete selected" >
</form>
where Submit() has something like this:
var con = confirm("Do you want to make the deletion?");
if(con=='true')
{
window.open('Posting.php','My Posting');
....
}
On the top of the page I also have something like this:
if($_POST['submit_del]=="Delete selected")
{ .... }
Inside of if statement, it is the mysql code to actually delete the rows.
Even the user answers no for that 'confirm()', those checked rows still get deleted. I know the reason is that the code 'if($POST['submit_del]=="Delete selected")' will always get executed because the delete button is clicked. I tried to only create or direct to the page Posting.php in the JavaScript. It's not working, and I'm afraid that $POST['submit_del] won't be set if only JavaScript is used.
In short, my question is how to make a confirmation (its better to do this at client side) and then use PHP to do what is required after clicking a button if the confirmation is affirmative.
Thanks.