When my form doesn't validate, I want to disable the form's submit function.
I can do this by disabling the submit button, but this would leave the enter key unchecked.
I can set the .submit(return false); but then I can't re-enable it again later.
Any suggestions?
Given an HTML document and the task is to enable or disable the form submit button in jQuery. Approach: To enable or disable the form submit button, we use the below code snippet. $('#enabled'). click(function () { if ($('#submit-button').is(':disabled')) { $('#submit-button').
How do you disable button until all fields are entered? Just click f12 in your browser, find the submit button in the html, and then remove the disabled ! It will submit the form even if the inputs are empty.
We use the preventDefault() method with this event to prevent the default action of the form, that is prevent the form from submitting.
just a simplification of Pim's (edited to pull up James contribution):
$('#form').submit(formValidated);
I did the following, which worked (disable submit button and form submit):
var condition = true; //check whatever you like
if(condition)
$('input[type=submit]', this).attr('disabled', 'disabled');
$('form').bind('submit',function(e){e.preventDefault();});
}else{
$('input[type=submit]', this).removeAttr('disabled', 'disabled');
$('form').unbind('submit');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With