Abhi
Abhi

Reputation: 299

disable the submit button after it clicked once

Here is my client website http://www.tswanda.co.zw/campaigns/tswanda-childrens-home/ when you click on contribute now a popup window appear with donate button, if you click on donate button 2, 3 or 4 times it submitted the value again for checkout.

I want to disable button once a money is submitted can you please help me out i tried hard use code from Disabling links to stop double-clicks in JQuery but nothing work for me.

any help will be really appreciated.

<script type="text/javascript">
       function do_nothing() { 
            return false;
           }

           // prevent a second click for 10 seconds. :)
                jQuery('.edd-add-to-cart').live('click', function(e) { 
                    jQuery(e.target).click(do_nothing); 
                      setTimeout(function(){
                     jQuery(e.target).unbind('click', do_nothing);
                    }, 50000); 
                  });


    </script>

Upvotes: 1

Views: 1064

Answers (3)

mohamedrias
mohamedrias

Reputation: 18566

Inside your click handler,You are binding another click event to the target. And you're removing that particular click handler.

Instead the try disabling the button by setting up disabled attribute and remove it.

function do_something() {
    alert("doing something");   
}

// prevent a second click for 10 seconds. :)

jQuery('.edd-add-to-cart').live('click', function (e) {
      var self = this;
      $(this).attr("disabled", "disabled");
      do_something();
      setTimeout(function () {
          $(self).removeAttr('disabled');
      }, 10000);
  });

DEMO

Upvotes: 0

Navjot Singh
Navjot Singh

Reputation: 514

try this

<input type="submit" name="Submit" value="Submit" onclick="this.disabled=true; this.value='Please Wait...';" />

Upvotes: 0

hamed
hamed

Reputation: 8033

You can disable the button when clicked, and re-enable it after 5 seconds:

         jQuery('.edd-add-to-cart').live('click', function(e) { 
             var element = $(this);
             jQuery(e.target).click(do_nothing); 
             element.attr("disabled", "disabled");
             setTimeout(function(){
                 element.removeAttr("disabled");
             }, 50000); 
          });

Upvotes: 1

Related Questions