JavaScript Confirm Box

2 Comments

Many times, in life, one needs to confirm things. For example, you might be writing a UI for a nuclear submarine and you need to add a confirm box whether the link should be followed (which might as a result launch a nuke or delete a record) or not. You can do it the hard way by writing PHP/ASP code but I like to do it the easy way, by using JavaScript.

A really simple approach is:

 html |  copy code |? 
1
<a href="nuke.php?launch=yes" onclick="return confirm('Are you sure you want to destroy humanity?')">Delete</a>

When the user clicks on it, this will produce the a pop up box, displaying that message and two buttons. If the user click yes, the link is followed otherwise nothing happens, and we live again ;)