2

As an HTML newbie I was doing some research on HTML forms in general, and action & onsubmit in particular, and Google gave me the following hit:


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?

Sandeep
  • 1,245
  • 1
  • 13
  • 33
  • **DO NOT post images of code, data, error messages, etc.** - copy or type the text into the question. [ask] – Rob May 29 '22 at 10:04

1 Answers1

5

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.

LittleOldMe
  • 188
  • 1
  • 10