unistake Posted October 18, 2010 Share Posted October 18, 2010 Hi all, I have a link that when clicked I it shows a popup box and depending on whether the user clicks yes or no the user script will continue to a php processing page to delete a record. I have made the popup box as shown below but if you click yes OR no the record is still deleted! How can I cancel the page being redirected if the user clicks no? (The backslashes are for the PHP code in the link) Thanks </style> <script type="text/javascript"> <!-- function confirmation() { var answer = confirm("Are you sure you want to delete the advert?") if (answer){ alert("Your advert has been deleted!") } else{ } } //--> </script> <body> <a href=\"manage-aircraft.php?reg=$reg\">$title</a> <a href=\"works/deleteadvert.php?reg=$reg\" onclick=\"confirmation()\"><img src=\"images/delete.png\" alt=\"Aircraft For Sale\" width=\"15\" height=\"15\" /></a><br>"; </body> Link to comment https://forums.phpfreaks.com/topic/216182-pop-up-box-confirmation/ Share on other sites More sharing options...
Bodhi Gump Posted October 18, 2010 Share Posted October 18, 2010 The href is always called after the onclick function ends. Try this. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> <script type="text/javascript"> <!-- function confirmation() { var answer = confirm("Are you sure you want to delete the advert?") if (answer){ document.myform.submit(); } } //--> </script> </head> <body> <form name="myform" action="sandbox.php"></form> <button onclick="javascript:confirmation();">CLICK ME</button> </body> </html> Link to comment https://forums.phpfreaks.com/topic/216182-pop-up-box-confirmation/#findComment-1123564 Share on other sites More sharing options...
haku Posted October 19, 2010 Share Posted October 19, 2010 function confirmation() { var answer = confirm("Are you sure you want to delete the advert?") if (answer){ alert("Your advert has been deleted!") } else{ return FALSE; } } Link to comment https://forums.phpfreaks.com/topic/216182-pop-up-box-confirmation/#findComment-1123672 Share on other sites More sharing options...
Bodhi Gump Posted October 19, 2010 Share Posted October 19, 2010 @haku That's strange, I've tried: function confirmation() { var answer = confirm("Are you sure you want to delete the advert?") if (!answer){ return FALSE; } } ...yet if I say no (cancel), the browser still opens to the href path. Link to comment https://forums.phpfreaks.com/topic/216182-pop-up-box-confirmation/#findComment-1123968 Share on other sites More sharing options...
unistake Posted October 21, 2010 Author Share Posted October 21, 2010 I have got it working thanks. Link to comment https://forums.phpfreaks.com/topic/216182-pop-up-box-confirmation/#findComment-1124830 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.