Confirming a user's action

Jake Howlett, 29 September 2000

Category: Quick Tips; Keywords: onclick return confirm delete

If you have links whose action is irreversible and you want to make the user confirm what they are doing then you could use the JavaScript onclick event.

The HTML to invoke this is:

<a href="../ViewName/DocID?DeleteDocument" onclick="return confirm('Are you sure you want to delete this document?');">Delete Document...</a>


Image

The onClick event will return either of two values depending on whether the user clicks 'Ok' or 'Cancel':

true - the link should be opened;
false - do not be opened;