jQuery to prevent multiple submit on a form


/ Published in: jQuery
Save to your folder(s)

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).


Copy this code and paste it in your HTML
  1. $(document).ready(function() {
  2. $('form').submit(function() {
  3. if(typeof jQuery.data(this, "disabledOnSubmit") == 'undefined') {
  4. jQuery.data(this, "disabledOnSubmit", { submited: true });
  5. $('input[type=submit], input[type=button]', this).each(function() {
  6. $(this).attr("disabled", "disabled");
  7. });
  8. return true;
  9. }
  10. else
  11. {
  12. return false;
  13. }
  14. });
  15. });

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.