I have two submit buttons on the same form for edit and delete and I want to make delete confirmation alert. I've tried but this only work yes however I select "no/cancel" in delete confirmation. What should I do ?
This is the form
<form name="form" method="POST" action="update.php">
//form code
<input name="update_button" type="submit" value="Update" />
<input type="submit" name="delete_button" onClick="javascript:confirmDelete();" value="Delete"/>
This is the javascript
<script type="text/javascript">
function confirmDelete()
{
var status = confirm("Are you sure you want to delete ?");
if(status)
{
parent.location.replace("parent.location='<?php echo "update.php";?>'");
}else
{
parent.location.replace("parent.location='<?php echo "form.php?ticket=".$c['no'] ?>'");
}
}
</script>
And this is the update.php
if(isset($_POST['update_button']))
{
//update proses
}
else if(isset($_POST['delete_button']))
{
//delete proses
}
I want delete confirmation show "Are you sure you want to delete ?" if I select "yes", it would delete from database and if I choose "Cancel", it will stay at current page (form.php).
Thanks before,