I'm trying to validate a form after clicking the submit button, so I'm preventing the form from automatically posting and refreshing the page with preventDefault()
. After calling preventDefault()
, I call another function to validate, like so:
$("#submit").click(function(e) {
e.preventDefault();
validate();
});
Here, #submit
is the ID for the submit input element.
At the end of validate()
, I try to call submit()
on the form element #homeForm
, but it doesn't seem to fire.
validate() {
....
console.log('test'); // this is firing
$('#homeForm').submit();
}
I used a few other Stack Overflow answers including this one to arrive at this solution, but I'm not really sure why it's not working. What could be preventing the submit()
function from firing?
Edit: I've added a bit of what this form looks like in the HTML
<form id="homeForm">
....
<input id="submit" class="submit" type="submit" name="submit" value="Submit" action="javascript:void(0);">
</form>