[Javascript] disabling form on submit

Paul Novitski paul at novitskisoftware.com
Mon May 24 12:24:55 CDT 2004


At 09:52 AM 5/24/2004, Hugo Ahlenius wrote:
>My idea is to have an include that disables all the form elements on
>submit of the form (to signal that it is processing, and to prevent the
>user from pressing the submit button multiple times).
>
>My problem is that   if the form elements are disabled before the
>submit, then they are not sent to the action Url (expected behaviour).


Hugo,

I've always had good success disabling the submit button alone.  I suppose 
it *might* be possible to change the value of input fields after clicking 
submit and have the changed values communicate to the server (if the typist 
is very quick or the browser is very slow), but I've never had a problem 
with that.

Below is my quickie suggestion (sorry no time to test it).

Paul
_______________________________

// set up the event when the page has loaded
window.onload = jsSubmitOnceInit

// set up the submit button
function jsSubmitOnceInit()
{
         var oSubmit = document.getElementById("SubmitOnce")
         oSubmit.onclick = jsSubmitOnce
}

// when button is clicked, disable it before submitting form
function jsSubmitOnce()
{
         this.enabled = false
         this.form.submit()
}
...
<input type="submit" id="SubmitOnce">






More information about the Javascript mailing list