Welcome to WebmasterWorld Guest from 54.198.118.102

Forum Moderators: open

Message Too Old, No Replies

Way to disable submit button once pressed?

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

Junior Member

10+ Year Member

joined:Dec 29, 2004
posts:153
votes: 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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2004
posts:2047
votes: 0


Put this on the submit button:

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

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

Junior Member

10+ Year Member

joined:Dec 29, 2004
posts:153
votes: 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 June 1, 2005 (gmt 0)

Senior Member from US 

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

joined:Dec 9, 2003
posts:3416
votes: 0


Just change the order:

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

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

Junior Member

10+ Year Member

joined:Dec 29, 2004
posts:153
votes: 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 June 4, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 29, 2004
posts:153
votes: 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 June 4, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:May 24, 2005
posts:554
votes: 0


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

HTML:

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

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 June 4, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 29, 2004
posts:153
votes: 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.

Thanks!

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

Junior Member

10+ Year Member

joined:Dec 29, 2004
posts:153
votes: 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?

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members