Skip to content

Instantly share code, notes, and snippets.

@akovalyov
Last active December 19, 2015 05:59
Show Gist options
  • Save akovalyov/5908597 to your computer and use it in GitHub Desktop.
Save akovalyov/5908597 to your computer and use it in GitHub Desktop.
simple jquery snippet for preventing double submits in form
(function (jQuery) {
/**
* prevents double submits
*
* usage
*
* just fire on document.ready, i.e.
* $(function(){
* $.preventDoubleSubmit()
* });
*/
jQuery.preventDoubleSubmit = function () {
jQuery('form').each(function () {
jQuery(this).submit(function () {
if (this.beenSubmitted) {
return false;
}
else {
this.beenSubmitted = true;
jQuery(this).find('[type=submit]').attr('disabled', 'disabled');
}
});
});
};
})($);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment