Only those with event handlers, and even then we could make do with only the FORM having an id if we wanted.The next step is to define and assign our event handling functions.The second button restores the initial state: In the default state, clicking on the Submit button will call our form validation script (see below) to make sure that all the fields have been populated.If that is not the case then there is an alert message and the script halts.A quick fix for this is to add an In this scenario the first click on the link will function normally taking the user to the target href.At the same time it adds a new event listener to capture and disable future clicks on the same link.The reason to use Java Script is that it disables the submit button instantaneously. I have some field validation, can I disable submit button after all validations are OK?A system of single-use client/server tokens can do this as well if you want to avoid relying on Java Script. This is a good solution, HOWEVER, it doesn't really stand well in 2013.
In this example, you can click the first button as many times as you want.The trick is to use Java Script to set the in a text input field - the submit button will be disabled to prevent double-clicking.If you're already using Java Script form validation then the command can instead be added to the script as follows: It's important that the command to disable the button be added at the end of the script, otherwise, if the validation fails, the user will have no opportunity to re-submit the form.Rather than simply disabling the button, we can also change the text so that people don't get confused.This example first disables the button and then changes the label from "Submit" to "Please wait...".
handler first checks to see whether the form is already in the process of submitting (second click).