最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Prevent double click on form submission - Stack Overflow

programmeradmin3浏览0评论

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

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

Share Improve this question asked May 20, 2014 at 6:27 TK91TK91 331 gold badge2 silver badges8 bronze badges 4
  • 2 two conflicting questions, may be jsfiddle would be better to understand.... – Bhojendra Rauniyar Commented May 20, 2014 at 6:29
  • 1 second click or double click? – Ravinder Gujiri Commented May 20, 2014 at 6:32
  • i want prevent double click. but if he keep blank field the required field validation will e and the button will disable. i want the button only disable on double click not when validation check. – TK91 Commented May 20, 2014 at 6:32
  • try this jsfiddle/thiagobraga/WZRK3 – Ravinder Gujiri Commented May 20, 2014 at 6:44
Add a ment  | 

3 Answers 3

Reset to default 7

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.

发布评论

评论列表(0)

  1. 暂无评论