I want to prevent multiple submit if someone click on one of the submit buttons multiple times.
How can unbind
or undelgate
in this case the call of my custom function do_some_stuff
that is only happens one time, because I try some of the jquery methods, but I think I did something wrong. Thanks
$(function() {
$('div.ajax').delegate('form button', 'click', function(e) {
$(this).do_some_stuff();
e.preventDefault();
});
});
The code: jQuery. validator. setDefaults({ submitHandler: function(form){ // Prevent double submit if($(form).
on() method is the preferred method for attaching event handlers to a document. To answer your question about multiple submits, another new addition in JQuery 1.7 is the . one() handler which, attaches an event handler to an object but only allows it to be fired once. This will allow you to prevent multiple submits.
You can as well prevent this by having a unique field like email/username or registration number. Then test then new field against the existing one in the DB, and if it matches, then the user has registered before, and form submission should stop, otherwise continue submitting form.
Bind and unbind are deprecated in JQuery.
As of jQuery 1.7, the .on()
method is the preferred method for attaching event handlers to a document.
http://api.jquery.com/on/
To answer your question about multiple submits, another new addition in JQuery 1.7 is the .one()
handler which, attaches an event handler to an object but only allows it to be fired once. This will allow you to prevent multiple submits.
e.g:
$("form#form1").one("submit", submitFormFunction);
function submitFormFunction(event) {
event.preventDefault();
$("form#form1").submit();
}
Note I'm binding to the form submit event rather than a button click event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With