Advertisement
Home Open Editor ❯

HTML formaction Attribute

Example

<form action="action.php" method="get">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname"><br><br>
  <button type="submit">Submit</button>
  <button type="submit" formaction="action2.html">Submit to another link</button>
</form>

Try this code ❯

Meaning

The formaction attribute specifies a URL to target when the button/input is clicked, similar to the use of the action attribute on a form element.

Note: The formaction attribute is only used with type="submit".


Standard Syntax

<element formaction="URL">


Applies to:

The formaction attribute can be used on the following element:


Advertisement

Attribute Values

Value Description
URL

Value can be

  • An absolute URL - navigate to within or another web site ( href="http://www.example.com/index.html")
  • A relative URL - navigate to within a web site ( href="index.html")

More Examples:

Example

<form action="action.php">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"><br><br>
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname"><br><br>
  <input type="submit" value="Submit">
  <input type="submit" formaction="action2.php" value="Submit to another page">
</form>

Try this code ❯

Home Open Editor ❯
Advertisement