Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Way to disable submit button once pressed?



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

10+ Year Member

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)

WebmasterWorld Senior Member 10+ Year Member

Put this on the submit button:

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


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

10+ Year Member

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)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

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)

10+ Year Member

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)

10+ Year Member

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)

10+ Year Member

<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)

10+ Year Member

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)

10+ Year Member

'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?


Featured Threads

Hot Threads This Week

Hot Threads This Month