Introduction
When a user on web form presses "Submit" button for sending data to web server, then the web server runs a script, query, etc. This may take uncertain time up to 1 minute. But the user sees a static page and may think: "I did not press the button or something is wrong" and press the button again many times. So the web server may get many HTML queries. This will increase CPU usage on the server and may return incorrect results.
Background
The idea is simple.
- Step 0 (may skip): Check the form: run function "
OnSubmit
" in tag FORM, check tag INPUT ("required" and "pattern" attributes). - Step 1: Change text on the button to "Please wait...".
- Step 2: Disable the button.
- Step 3: Send query.
Using the Code
Just add code to input tag:
<input type="submit" name="Submit" value="Submit"
önclick = "this.form.check(); this.value='Please wait...'; this.disabled=true; this.form.submit();" />
So see 'on click' event.
Step 0. Check the Form
this.form.check();
Step 1. Change Text on the Button
this.value='Please wait...';
Step 2. Disable the Button
this.disabled=true;
Step 3. Press the Button Programmatically
this.form.submit();
Points of Interest
See also:
History
- 1.1 | Added Step 0: Check form | 06.05.2013