Consider the following code:
HTML
<a href='#' id='the-button'>Submit</a>
JavaScript
$("#the-button").click(function(e) {
e.preventDefault();
$("#the-form").submit();
});
$("#the-form").submit(function(e) {
//stuff here
});
when the ‘#the-button’ is clicked and the form is submitted, the ‘submit’ event handler does not fire. Is there any way to attach an event handler to a form so that it fires even if it is not submitted via the submit button?
Change
$("#the-form").submit();to$("#the-form").trigger('submit');Edit: However, like @wirey said, the code you posted should work, unless there is some other code interfering.