...

View Full Version : JS to disable form submit button?



jeanne
07-07-2003, 06:24 PM
I would like to make sure users do not click the submit button on my form more than once.

Is there some way to do this using Javascript?



:)thankx for your input!

arnyinc
07-07-2003, 06:32 PM
<form onsubmit="document.getElementById('mysub').disabled=true;">

<input type="submit" id="mysub">

</form

Vladdy
07-07-2003, 07:08 PM
More than once, per page visit or more than once a day/week/month/year?
The code above will take care of preventing someone from submitting the form twice per page visit, but it would take a simple page refresh to get around it.

brothercake
07-07-2003, 07:13 PM
It's a useful trick though - it's amazing how many people double-click buttons and hyperlinks, and this can prevent forms from being submitted twice by mistake - with stuff like credit card purchases that can be quite serious.

jeanne
07-07-2003, 07:22 PM
once per page visit is fine for a limit.

i tried implementing the code above but my form just wouldnt submit at all...

am still working on it.

Vladdy
07-07-2003, 07:30 PM
It will prevent repeated form submition using the "submit" button, but will not help when user presses "enter". I would use cookies for the task - maybe a bit extra work up front, but sure allows for much more flexibility if needed...

beetle
07-07-2003, 08:17 PM
Try this
<form onsubmit="this.elements['mysub'].disabled=true;return true;">

<input type="submit" name="mysub">

</form>Vladdy -- what? onsubmit is fired by any submission except one triggered by the form's submit() method.

Vladdy
07-07-2003, 08:31 PM
You are right - brainfart on my part.... :o



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum