Posted By

dalexandre on 08/02/09


Tagged

javascript jquery submit multiple disabled jquerydata


Versions (?)

Who likes this?

11 people have marked this snippet as a favorite

frontend_P
Meander365
Jdub7
legacye
derekholmes
asifroyal
jfherring
orhanveli
sethetter
Kurt
ringo380


jQuery to prevent multiple submit on a form


 / Published in: jQuery
 

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

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

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

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Jdub7 on August 13, 2009

Add this above line 6. Disabled removes the values also. This allows for the value of the submit button to be passed along with the form.

            $(this).clone().attr('type','hidden').insertBefore(this);

You need to login to post a comment.