简体   繁体   中英

Prevent double click on form submission

I want to prevent double click on submit button.

My code is...

onclick='this.style.visibility = "hidden";'

But it also hidden if i enter wrong entry. I want to disable button on double click but button enable in validation wrong entry

use this instead :

onclick="this.disabled=true;"

And for Double click event you could use :

ondblclick="this.disabled=true;"
  jQuery.fn.preventDoubleSubmission = function() {

var last_clicked, time_since_clicked;

$(this).bind('submit', function(event){

if(last_clicked) 
  time_since_clicked = event.timeStamp - last_clicked;

last_clicked = event.timeStamp;

if(time_since_clicked < 2000)
  return false;

return true;
});
};

Using like this:

 $('#my-form').preventDoubleSubmission();

Prevent double submission of forms in jQuery

Your question is not clear. But based on my understanding, the tips below may help you.

To disable button on double click you can write code for that in .dblclick() jquery event. if there is any validation error, enable the button again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM