2

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

TK91
  • 33
  • 1
  • 2
  • 8

3 Answers3

7

use this instead :

onclick="this.disabled=true;"

And for Double click event you could use :

ondblclick="this.disabled=true;"
Runcorn
  • 5,144
  • 5
  • 34
  • 52
  • i want prevent double click. but if he keep blank field the required field validation will come and the button will disable. i want the button only disable on double click not when validation check. – TK91 May 20 '14 at 06:33
  • i want to avoid double data entry – TK91 May 20 '14 at 06:42
5
  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

Community
  • 1
  • 1
Kaja Mydeen
  • 585
  • 1
  • 7
  • 13
0

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.

Joby Joseph
  • 2,177
  • 3
  • 15
  • 19