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
3 Answers
Reset to default 7use 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.