HTML <form> action Attribute

The action attribute on a <form> tag specifies the form-handler that will process the submitted form data.

Example

#

An action attribute on a <form> element.
Form data will be submitted to the specified form-handler.





<form action="/tutorial/action.html">
  <label>Enter your name</label> <br />
  <input type="text" name="firstname" placeholder="First name"><br />
  <input type="text" name="lastname" placeholder="Last name"><br /><br />

  <button type="submit">Submit</button>
</form>

Using action

The action attribute specifies where to send the form data when submitted.

Form data is mostly submitted to a server-side handler, but it can also be JavaScript on the client.


Syntax

<form action="URL">

Values

#

Value Description
URL An internal (same domain) or external (different domain) URL.
It can also be a JavaScript function.

More Examples

A <form> with a JavaScript action.
Clicking submit executes a client-side Javascript function.






<form action="javascript:submit()">
  <label>Enter your address</label> <br />
  <input type="text" name="street" placeholder="Street"><br />
  <input type="text" name="city" placeholder="City"><br />
  <input type="text" name="state" placeholder="State"><br /><br />

  <button type="submit">Submit</button>
</form>

<script>

  let submit = () => {
    let values = "";
    values += "Street = " + document.getElementsByName("street")[0].value + "\n";
    values += "City = " + document.getElementsByName("city")[0].value + "\n";
    values += "State = " + document.getElementsByName("state")[0].value + "\n";
    alert(values);
  };

</script>

Browser support

Here is when action support started for each browser:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like

 Back to <form>
Guides