jquery - Function to avoid double click not working with input submit on chrome only -


this code avoid double clicks on form submit disabling button few second settimeout

it works on ie & firefox form never submits on chrome

<input type="submit" id="button" class="button" onclick="foo(this);" name="submit_forgot" value="submit" /> 

and here function:

  function foo(obj) {     obj.disabled = true;     settimeout(function() {         obj.disabled = false;     }, 2000);     } 

thanks help!

i'd use data support multiple buttons, if need be.

$("#button").click(function () {    if ($(this).data("disable")) {      return false;    }    $(this).data("disable", true);        clearinterval($(this).data("interval"));        $(this).data("interval", setinterval(function () {      $(this).data("disable", false);    }.bind(this), 2000));        console.log("called");  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <input type="submit" id="button" class="button" name="submit_forgot" value="submit" />


Comments