How to use jQuery to Prevent Multiple Form Submit for Efficient Forms

How to use jQuery to Prevent Multiple Form Submit for Efficient Forms


use jQuery to Prevent Multiple Form


Often when a jQuery form is submitted, it can accidentally happen more than once. Depending on the server speed or the internet connection, the request to submit the form can go through slowly, which often leads to the user hitting the submit button more than once because they may think it isn't working. When this happens, the form can be submitted multiple times, which isn't a huge deal, but can definitely lead to some clogging up of your inbox.

A really good way to prevent this from happening is to use some simple jQuery code that disables the submit button after it's been submitted. The code to add this functionality to any of your projects is efficient, lightweight, and less than 15 lines.





  $('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;


    }


  });


When adding it to any of your projects, don't forget to add the specific form class or ID for the form you want to target if you don't want or need this snippet to apply to all the forms on your site.

So that I can say about How to use jQuery to Prevent Multiple Form Submit for Efficient Forms, may be useful. Make sure you keep visiting Bloggers Aim to have this guide to bloggers and SEO information. If you do not want to miss the article that I will post at the next opportunity, please subscribe via email through the form to subscribe at the bottom of this blog, and before you navigate away from this page, I am very glad if you are willing to give Like, Share and give G +1 on this article so that other blogger friends also know this information. I say thank you in advance, may be useful and success always for you.

Ads middle content1

Ads middle content2