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? Thanks <head> </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> </head> <body> <?php echo "<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/216183-pop-up-box-confirmation-problem/ Share on other sites More sharing options...
Colton.Wagner Posted October 18, 2010 Share Posted October 18, 2010 That is actually a javascript problem but I would say redirecting the user page to the page with no other header information being sent should void the query. Thanks, Colton Wagner Link to comment https://forums.phpfreaks.com/topic/216183-pop-up-box-confirmation-problem/#findComment-1123543 Share on other sites More sharing options...
schilly Posted October 18, 2010 Share Posted October 18, 2010 you have no return so the link will always go through. function confirmation() { var answer = confirm("Are you sure you want to delete the advert?") if (answer){ alert("Your advert has been deleted!"); return true; } else{ return false; } } I usually just do this: <a href="link" onClick="return confirm('Are you sure you want to delete the advert?');">Link</a> Link to comment https://forums.phpfreaks.com/topic/216183-pop-up-box-confirmation-problem/#findComment-1123546 Share on other sites More sharing options...
unistake Posted October 18, 2010 Author Share Posted October 18, 2010 ok i'll give it a go thanks. Link to comment https://forums.phpfreaks.com/topic/216183-pop-up-box-confirmation-problem/#findComment-1123549 Share on other sites More sharing options...
unistake Posted October 18, 2010 Author Share Posted October 18, 2010 A ot simpler and works great, thanks Link to comment https://forums.phpfreaks.com/topic/216183-pop-up-box-confirmation-problem/#findComment-1123571 Share on other sites More sharing options...
unistake Posted October 18, 2010 Author Share Posted October 18, 2010 Actually it works, however it does not delete the record in mysql. It was working fine before I put this popup box confirmation in so the code is good. I think it may have something to do with this line: <?php echo "<a href=\"manage-aircraft.php?reg=$reg\">$title</a> <a href=\"works/deleteadvert.php\" onClick=\"return confirm('Are you sure you want to delete the advert?');\"><img src=\"images/delete.png\" alt=\"Aircraft For Sale\" width=\"15\" height=\"15\" /></a><br>"; ?> The $reg value is not being passed on to the deleteadvert.php page. Do you know why the $reg value would not be passed to the processing page with this alert box? Thanks Link to comment https://forums.phpfreaks.com/topic/216183-pop-up-box-confirmation-problem/#findComment-1123615 Share on other sites More sharing options...
schilly Posted October 18, 2010 Share Posted October 18, 2010 you dont have any $reg value in your link <a href=\"works/deleteadvert.php\" Link to comment https://forums.phpfreaks.com/topic/216183-pop-up-box-confirmation-problem/#findComment-1123618 Share on other sites More sharing options...
unistake Posted October 18, 2010 Author Share Posted October 18, 2010 Ofcourse, thanks Link to comment https://forums.phpfreaks.com/topic/216183-pop-up-box-confirmation-problem/#findComment-1123622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.