How to prevent HTML form from submitting multiple times
If you want to prevent the HTML form from being submitted two (or more) times, you can use this simple solution.
Let's say there is a simple form:
<form method="POST" action="..." id="myForm">
...
<input type="submit" name="sendButton" value="Send">
</form>
jQuery code to prevent the form from being submitted again:
<script type="text/javascript">
$("#myForm").submit(function(){
// if more than 1 time:
$(this).submit(function() {
return false;
});
return true; //if 1st time
});
</script>
myForm - this is the id of the form, by which the script determines which form the script should be applied to, so be careful - both the ID must match.
Comments