2

When I use the DOM form submit method to submit a form, the jQuery submit event handler isn't called, even though w3c says: "It performs the same action as a submit button."

I tried with jQuery 1.11.0 and 2.1.0.

<form id="form">
    <button type="button" onclick="document.getElementById('form').submit()">submit onClick</button>
</form>

See http://jsfiddle.net/g0kxmdmw/6/ for a full example.

In both Firefox and Chrome, pressing enter in the text input, clicking "submit button" and "submit jquery" will all trigger the handler and cancel the form submit, while "submit onClick" and "submit js dom" don't trigger the handler, and will perform the submit (a GET request).

I expected that calling the submit method would show the same behaviour as clicking a submit button, but it doesn't. Is this a bug in jQuery?

1 Answer 1

2

No, calling the form's submit() method does not trigger the submit event so none of the event handlers will get triggered.

The submit event will be fired only when the user triggers it via a button click or any such actions.

submit event

The form's onsubmit event handler (for example, onsubmit="return false;") will not be triggered when invoking this method from Gecko-based applications. In general, it is not guaranteed to be invoked by HTML user agents.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.