How to disable button after it's pressed?
Moderator: General Moderators
How to disable button after it's pressed?
I've seen this done before.
I'd like to disable the button after it's pressed to prevent multiple submissions. Is there a JS script to do this?
I'd like to disable the button after it's pressed to prevent multiple submissions. Is there a JS script to do this?
long live websearches, for example i searched for "html button disable"
http://www.quirksmode.org/js/disabled.html
http://www.quirksmode.org/js/disabled.html
I've been experimenting with adding this bit of code in the input type=submit line:
It does indeed disable the form button after its pressed, but I found that even though other POSTed data was sent to the server, the submit line itself is not.
This I gathered from Tim's link above.
Any ideas for a work-around?
Code: Select all
onClick="e;this.disabled=true;return true;"e;This I gathered from Tim's link above.
Any ideas for a work-around?
-
R0d Longfella
- Forum Newbie
- Posts: 20
- Joined: Fri Apr 08, 2005 7:17 am
If you want to make sure that the data is only send once, then why don't you use onSubmit?
You could even put in an extra alert.
Code: Select all
<script>
var bSubmitOnlyOnce = false;
function testSubmitOnlyOnce () {
if (bSubmitOnlyOnce) {
// alert ("Data already submitted!");
return false;
}
bSubmitOnlyOnce = true;
return true;
}
</script
<form onSubmit="return testSubmitOnlyOnce();">
<input type=submit name="save" value="Submit Data">
</form>Indeed, disabled form items are not send. A simple solution is to use hidden fields instead sending the value of the submit button.voltrader wrote:I've been experimenting with adding this bit of code in the input type=submit line:
It does indeed disable the form button after its pressed, but I found that even though other POSTed data was sent to the server, the submit line itself is not.Code: Select all
onClick="e;this.disabled=true;return true;"e;
This I gathered from Tim's link above.
Any ideas for a work-around?
There are 10 types of people in this world, those who understand binary and those who don't
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
A more user-friendly way of doing that is to force a submission in the function, then disable the button so the users are at least aware. I, personally, don't condone doing this client-side though, because a user can always press the stop button. Sometimes the processing is slow, and trying again speeds it up.