Disable a form button when a form is submitted using JQuery

Snippet to disable a ‘Save’ button when I submit a form. This checks client side validation, and if the form is valid for submission, it will disable the ‘Save’ button to prevent multiple clicks, and it will POST the form.

 
 $(document).ready(function() {
   $("#saveButton").click(function (e) {
      var form = $(this).parents('form:first');
      if ($(form).valid()) { 
         this.disabled = true;
         $(form).submit();
     } 
  }); 
}); 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s