Home > Blockchain >  HTML form: action vs onsubmit
HTML form: action vs onsubmit

Time:05-31

As an HTML newbie I was doing some research on HTML forms in general, and action & onsubmit in particular, and Google gave me enter image description here


Naturally my first reaction was to take this at its face value but then upon clicking the link I discovered that this answer had been downvoted. So obviously the first hit from Google is not accurate.

Can we kindly have the correct answer to this question so that hopefully it can be promoted to the top of any subsequent Google search?

CodePudding user response:

if I am not mistaken:

The action is an attribute that specifies where to send the form-data when a form is submitted. (aka what is the 2nd page that is supposed to receive the form-data once this form is submitted)

<form action="/somewhere.php">
 //Form Elements
</form>

The onsubmit attribute is used to specify which JS code to run.

<form onsubmit="someFunction()">
    //Form Elements
</form>

To answer your question: onsubmit will always fire first.

  • Related