homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Way to disable submit button once pressed?

 11:11 pm on May 27, 2005 (gmt 0)

I'd like to prevent multiple submissions.

Anyone have a bit of script to disable the submit button after it's pressed?

I've seen this done before.


Bernard Marx

 1:12 pm on May 28, 2005 (gmt 0)

Put this on the submit button:

onclick="this.disabled=true;return true;"


 5:54 pm on Jun 1, 2005 (gmt 0)

Somehow I lose POST data when I use that JS clause in the submit like so:

<input type=submit name='sub' value='submit' onClick='this.disabled=true;return true;doSection(loading);'>

doSection displays an animated loading gif.


 6:47 pm on Jun 1, 2005 (gmt 0)

Just change the order:

<input type=submit name='sub' value='submit' onClick='this.disabled=true;doSection(loading);return true;'>


 6:54 pm on Jun 2, 2005 (gmt 0)

Thanks folks -- it's still not working. I've looked at the POSTed data with and without the JS and the contents look the same, but somehow the result is different.

The POSTed data with the submit-button-disabling-script is triggering my "invalid page request" routine, which basically looks at the POST/GET variables and checks whether or not that dynamic page exists. The difference has to be here, but I've stared at it too long over the past couple of days.

I'll have to let this one simmer a little before tackling it again.


 12:21 am on Jun 4, 2005 (gmt 0)

Figured out why my script stopped working as expected after I included the disable-submit-button clause.

Turns out that data from any field that's disabled is NOT sent to the server.

Any ideas for a creative work-around to prevent multiple button presses?


 1:14 am on Jun 4, 2005 (gmt 0)

<script language="JavaScript">
function submitPressed() {
document.someForm.submitButton.disabled = true;
//stuff goes here


<form name="someForm" action="whatever">
<input type="button" value="submit" name="submitButton" onclick="submitPressed()">

is a JS solution, not the best, if javascript is disabled etc.. but it works...

Would have to know what serverside you are using, as PHP or ASP solutions are more effective..


 3:26 am on Jun 4, 2005 (gmt 0)

Thanks for the script Lobo. I'm using PHP.

I could check for a duplicate entry, but since I'm also accepting large photo files, I'd rather try to disable onClick.

Unless you meant something else by remarking about server-side solutions.



 4:08 am on Jun 4, 2005 (gmt 0)

'Nother question about your script Lobo...

If the user has JS disabled, the submit-button is not disabled onClick and the form is still submitted, is that correct?

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved