Alkimuz Posted August 25, 2010 Share Posted August 25, 2010 i'm a little ashamed to asked something that is probably so easy, i tried to find the answer, but i am really a NOOB in javascript so i hope that i can ask you for a code that is ready to use.. i now have a code to delete an item in a website by pushing on a button. It goes to a new page wich has an SQL delete code. In short: echo '<a href="save.php?type=delete&item='.$item.'">delete</a> '; but now i really like to put a confirmation box between that, so after pushing the button, a message box appears asking: "Are you sure to delete this item?" and after clicking yes, it goes right away to that deletepage thanks very much in advance! Quote Link to comment Share on other sites More sharing options...
Adam Posted August 25, 2010 Share Posted August 25, 2010 Don't worry about it, everyone's been there. From within the onclick attribute of your link, call your confirmDelete() type function: echo '<a href="save.php?type=delete&item='.$item.'" onclick="return confirmDelete();">delete</a> '; Be sure to include the return part as this will prevent the page from redirecting if the return is false. Then your confirmDelete() function needs to be something like: function confirmDelete() { var c = confirm('Are you sure you want to delete this item?'); if (!c) return false; } Then that should be it. Although you should be aware not everybody has JS enabled, so that confirmation message won't appear for everyone. Quote Link to comment Share on other sites More sharing options...
Alkimuz Posted August 25, 2010 Author Share Posted August 25, 2010 Tanks so much! :D also for the extra explanation Quote Link to comment 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.