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

Avoid that a HTML FORM is submitted twice

Question:

What is the best way to make sure a user does not submit a form twice?

Answer:

The easiest way: Disable the submit button in the onclick() event. See the code for that in the box below.

You can also put some code in the form's onsubmit() event, as the second code snippet shows.

<!-- 
   disable the submit button after the first click: 
 //-->
 <input type="submit" onClick="this.disabled=true">
 
 
 <!--
   Note: the following goes all in one line. 
   This method sets a 'flag' (this.submitted) to 
   avoid multiple submissions of your form.
 //-->
 
 <form action=".." \
  onsubmit="if (this.submitted) return false; \
 else { \
 this.submitted = true; disableSubmits(this); \
 return true;}"

Generated 12:01:41 on Sep 23, 2018