Return to Snippet

Revision: 16373
at August 2, 2009 06:55 by dalexandre


Initial Code
$(document).ready(function() {
  $('form').submit(function() {
    if(typeof jQuery.data(this, "disabledOnSubmit") == 'undefined') {
      jQuery.data(this, "disabledOnSubmit", { submited: true });
      $('input[type=submit], input[type=button]', this).each(function() {
        $(this).attr("disabled", "disabled");
      });
      return true;
    }
    else
    {
      return false;
    }
  });
});

Initial URL
http://blog.damienalexandre.fr/index.php?post/2009/08/02/jQuery-eviter-la-soumission-multiple-d-un-formulaire

Initial Description
To prevent multiple submit from sending more than one request, 
bind the submit event and store a "disabledOnSubmit" data. Next time the event "submit" will be fire, the following jQuery code will return false. All submit buttons are also disabled (nice user feedback).

Initial Title
jQuery to prevent multiple submit on a form

Initial Tags
javascript, jquery

Initial Language
jQuery