How to implement a Javascript confirmation dialog on a href-link

Link deletion confirmationSometimes is desirable to have a confirmation on a delete link, just incase the user has clicked the wrong item.

So when you have a html link like this :

<a href="go.php?id=123">Delete</a >

Simply change it to do the following :

<a href="go.php?id=123" onclick="return confirm('Are you sure you wish to delete this item?');">Delete</a>

Of course, this is only going to work if the user has Javascript enabled.

Hope it save you some time.


Leave a Reply

Your email address will not be published. Required fields are marked *