When Written: Nov 2006
Whilst browsing the other day I ended up on the excellent site ‘Four Guys from Rolla’ ( http://www.4guysfromrolla.com ). This site has so many good articles on it that if you are working with ASP or ASP.NET it should be obligatory reading for you. The particular article I was interested in covered the problem of stopping the user clicking a submit button twice. By doing this it is possible to stop a lot of double postings from users into databases. This can be done with a little javascript code:
<script>
function DisableButton(b)
{
b.disabled = true;
b.value = 'Submitting';
b.form.submit();
}
</script>
And calling it when the user clicks the submit button
<input type="submit" name="SubmitButton" id="SubmitButton"
value="Submit"
onclick="DisableButton(this);" />
What happens when the user clicks the button on a web page is that the text on the button changes from ‘Submit’ to ‘Submitting’ and the button is disabled so further clicks on it will have no effect. Simple but effective
Article by: Mark Newton
Published in: Mark Newton