Event firing sequence for a submit button.

Posted by JSTyro on Stack Overflow See other posts from Stack Overflow or by JSTyro
Published on 2010-05-10T10:09:27Z Indexed on 2010/05/10 10:14 UTC
Read the original article Hit count: 198

Say a submit button has a click event handler as well (yes, it's wrong, but that's really the code I'm working on).

And the click handler sets a value in a field of the form that's about to be submitted.

So when the submit button is clicked:

  1. What will fire first, the form submit event or the click event?
  2. Will the value set in the form field by the click event submitted to the server? I think this depends on the answer to Q1. If the form is posted first, I'm guessing it won't.

Note: I'm not looking for alternatives and advice. I know what the proper way of handling this will be. Just trying to understand the sequence of events and their implications.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about javascript-events