Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable/enable entire form's submit with jquery

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?

like image 550
Boris Callens Avatar asked Mar 10 '09 14:03

Boris Callens


People also ask

How enable and disable the submit button in jQuery?

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 submit button until all fields are entered?

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.

How do I stop form submit in jQuery?

We use the preventDefault() method with this event to prevent the default action of the form, that is prevent the form from submitting.


2 Answers

just a simplification of Pim's (edited to pull up James contribution):


$('#form').submit(formValidated);
like image 177
Nick Franceschina Avatar answered Sep 21 '22 01:09

Nick Franceschina


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');
}
like image 21
Alexander Taubenkorb Avatar answered Sep 22 '22 01:09

Alexander Taubenkorb