Associate
- Joined
- 25 Aug 2004
- Posts
- 163
- Location
- Reading
I need a confirmation box in order to ascertain whether someone wants to delete something using a form. I've managed to get a confirmation page to redirect on both ok | cancel and go to the target page on ok | cancel. But haven't managed to delete on ok, and stay on the same page on cancel :\ !
Here's the code:
...and here's the form (it takes a dynamically generated php hidden field as a variable to pass to the delete page. I took the form action out as it defaulted to delete whatever the confirm box did and tried to pass it to the jscript to decide the form action.
I'm a jscript noob and have only ever done server side php and ASP before! I'm sure it's quite a simple solution and I'm being stupid, but found nothing on Google.
Thanks in adv.
Gareth
Here's the code:
Code:
<SCRIPT language="JavaScript">
<!-- function confirm_del()
{
var where_to= confirm("Do you really want to delete?");
if (where_to== true)
{
document.delete.action = 'delete.php';
document.delete.submit(); // Submit the page
}
else
{
document.delete.action = 'currentpage.php';
document.delete.submit(); // Submit the page
}
}
//-->
</SCRIPT>
...and here's the form (it takes a dynamically generated php hidden field as a variable to pass to the delete page. I took the form action out as it defaulted to delete whatever the confirm box did and tried to pass it to the jscript to decide the form action.
Code:
<form name="delete" method="post"> <input type="hidden" name="del_date" value="<?php echo $row['del_date'];?>"/> <input type="submit" value=" Delete " onclick="confirm_del()"/> </form>
I'm a jscript noob and have only ever done server side php and ASP before! I'm sure it's quite a simple solution and I'm being stupid, but found nothing on Google.
Thanks in adv.
Gareth