Alexhoward Posted January 19, 2009 Share Posted January 19, 2009 Hi guys, So, i'm pulling back images in a loop, and on each image i have a delete link that goes to something like: images.php?delete=1&id=28 so it will delete the image with an id of 28 from MySQL however i would like to have an "are you sure?" YesNo message box pop up. Does anyone know if this is possible? found a way through javascript but can't pass the variables as it calls a set function... Thanks in advance! Add Some Music http://www.addsomemusic.co.uk Quote Link to comment https://forums.phpfreaks.com/topic/141501-solved-php-confirm-message-box/ Share on other sites More sharing options...
rhodesa Posted January 19, 2009 Share Posted January 19, 2009 php can't do a confirm box. it can do a confirm page, but i'm pretty sure the Javascript confirm box is what you want. If they click Cancel, it should just stay on the page. what does your code look like right now for the delete links? Quote Link to comment https://forums.phpfreaks.com/topic/141501-solved-php-confirm-message-box/#findComment-740672 Share on other sites More sharing options...
Alexhoward Posted January 19, 2009 Author Share Posted January 19, 2009 Hi, Problem is, as i loop through the results i echo the images, then the href can use those results to link with. but with java script i have to use: <a href="#" onclick=" ConfirmChoice(); return false;"> which calls: <script language="javascript"> function ConfirmChoice() { answer = confirm("Are you sure you want to delete this gallery?") if (answer !=0) { location = "where ever" } } </script> Quote Link to comment https://forums.phpfreaks.com/topic/141501-solved-php-confirm-message-box/#findComment-740679 Share on other sites More sharing options...
daveoffy Posted January 19, 2009 Share Posted January 19, 2009 This may be a better way. I use this a lot <script>function delete() { var answer = confirm("Do you want to delete this gallery?") if (answer){ window.location = "http://site.com/to/where/you/want/to/delete"; } }</script> And the button to make this pop up is... <form><input type="button" onclick="delete()" value="Delete Gallery"></form> Quote Link to comment https://forums.phpfreaks.com/topic/141501-solved-php-confirm-message-box/#findComment-740684 Share on other sites More sharing options...
Alexhoward Posted January 19, 2009 Author Share Posted January 19, 2009 Thanks for the reply problem is i put the delete script on the same page, so... images.php?delete=1&id=28 will delete image 28 therefore the java location needs to have these variables...? Quote Link to comment https://forums.phpfreaks.com/topic/141501-solved-php-confirm-message-box/#findComment-740696 Share on other sites More sharing options...
premiso Posted January 19, 2009 Share Posted January 19, 2009 <script>function delete(id) { var answer = confirm("Do you want to delete this gallery?") if (answer){ window.location = "http://site.com/to/where/you/want/to/delete?delete=1&id=" + id; } }</script> <form><input type="button" onclick="delete(28)" value="Delete Gallery"></form> But if you are using a form you could just use that to submit the form. Quote Link to comment https://forums.phpfreaks.com/topic/141501-solved-php-confirm-message-box/#findComment-740698 Share on other sites More sharing options...
DeanWhitehouse Posted January 19, 2009 Share Posted January 19, 2009 $delete_id = 28; echo "<form><input type=\"button\" onclick=\"delete('$delete_id')\" value=\"Delete Gallery\"></form>"; Then <script>function delete(DeleteId) { var answer = confirm("Do you want to delete this gallery?") if (answer){ window.location = "http://site.com/?delete="+DeleteId; } }</script> That + might need to be changed to & Quote Link to comment https://forums.phpfreaks.com/topic/141501-solved-php-confirm-message-box/#findComment-740699 Share on other sites More sharing options...
daveoffy Posted January 19, 2009 Share Posted January 19, 2009 Where you have a link from the gallery to delete that gallery replace the link with that javascript button. Than you just change the javascript to this <script>function delete() { var answer = confirm("Do you want to delete this gallery?") if (answer){ window.location = "http://site.com/to/where/you/want/to/delete/images.php?delete=1&id='.$id.'"; } }</script> and set $id the the image ID Quote Link to comment https://forums.phpfreaks.com/topic/141501-solved-php-confirm-message-box/#findComment-740701 Share on other sites More sharing options...
Alexhoward Posted January 19, 2009 Author Share Posted January 19, 2009 Nice one! got it working, but can only get to work with numbers, not variables that are text Quote Link to comment https://forums.phpfreaks.com/topic/141501-solved-php-confirm-message-box/#findComment-740731 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.