DelphiFAQ Home Search:
General :: Programming :: JavaScript
Code snippets to add functionality to your HTML pages, preferably cross-browser.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Ask for a confirmation in Javascript before a critical action

Question:

How can I prompt a user to confirm critical actions like deleting records?

Answer:

Use the javascript confirm() function. It looks similar to the alert() box, but has an OK and a CANCEL button.
If the user clicks OK, confirm() will return true.
Otherwise - escape, or click on CANCEL - it will return false.

<script language="JavaScript">
 <!--
 function confirm_entry(user_name, delete_url)
 {
 input_box=confirm("Do you really want to delete user " + user_name);
 if (input_box==true) { 
   // clicked 'OK', so delete the record
}
 }
 -->
 </script>
 
 <a href="javascript:confirm_entry('peter', '/cgi-bin/delentry.pl?peter')">delete peter</a>
 

Generated 12:01:49 on Dec 11, 2017