Reputation: 531
I made a function where using e.preventDefault()
I stopped form submitting because I need first to check the values inside. How can I do to allowing submitting after that?
Upvotes: 0
Views: 30
Reputation: 20061
You could use e.preventDefault()
on a button, rather than an input with type submit.
So change the <input type="submit"/>
to a <button id="btnSubmit">Submit</button>
Then use an event handler to catch the event, and if it is successful, submit the form with $('form').submit();
, for example:
$('document').on('click','#btnSubmit',function(){
e.preventDefault()
//do your error handling
//if successful
$('#formId').submit();
}
Upvotes: 0
Reputation: 68400
Assuming you're handling form submit event, remove e.preventDefault()
so you can implement and alternative approach.
You should return false
when you want to cancel submit and simply continue with normal flow you don't. Example:
$('form').submit(function() {
if (!isFormInvalid()) {
// cancel form submit
return false;
}
// continue with function flow if form is valid
})
Upvotes: 2