0

I have a submit button, i need this button to be disabled after only one click , and it should be not disabled if there are validation errors. i am using the following,

onclick="var e = this; setTimeout(function () { e.disabled = true; e.value='Please wait...'}, 0); return true;"

but this makes the button remain disabled if there are validation errors which i don't want.

here is the submit button code

 <input type="submit" onclick="var e = this; setTimeout(function () { e.disabled = true; e.value='Please wait...'}, 0); return true;" value="Confirm Selected" /> 

How do i achieve this using jquery or JavaScript ?

Note: I have looked into stack overflow questions, but the answers don't handle when there is a validation errors.

this does not work after validation

The Scientific Method
  • 2,374
  • 2
  • 14
  • 25

2 Answers2

0

If you are using html validations like input tag with type email you should use form submit instead of button click because form only submits when there is no error in the form. for form submitting you can try as below:

$('form').on('submit', function(e){

});
Muhammad Aftab
  • 1,098
  • 8
  • 19
0

It really depends on the validation you are using and the way everything is set.

It might work for you if, instead of a timeout, you try with setInterval();

You can have a flag that is set to "disable" on button click you can also initiate the interval which will check for errors every N seconds. If there are no errors it will call a function that changes the submit button to the initial/new state, change the "disable" flag, and clear the interval.