Button formAction attribute

Definition and usage

formAction Sets or returns the formAction attribute of the button formaction attributevalue.

The formaction attribute specifies where to send form data when submitting the form. This attribute overrides the action of the HTML form action attribute.

The formaction attribute is only used for buttons with type="submit".

Note:In the following examples, Internet Explorer and Opera 12 (and earlier versions) return "action_page2.php", while Firefox, Opera 15+, Chrome, and Safari return the entire URL: "https://www.codew3c.com/action_page2.php".

Note:formaction attribute Is a new attribute of the <button> element in HTML5.

Instance

Example 1

Return the URL that sends form data when submitting the form:

var x = document.getElementById("myBtn").formAction;

Try it yourself

Example 2

Change the formaction attribute value of the button:

document.getElementById("myBtn").formAction = "/action_page2.php";

Try it yourself

Example 3

Another example of returning the formAction attribute:

var x = document.getElementById("myBtn").formAction;

Try it yourself

Syntax

Return the formAction attribute:

buttonObject.formAction

Set the formAction attribute:

buttonObject.formAction = URL

Attribute value

Value Description
URL

Specifies the location to send form data. Note: This will override the action attribute of the <form> element.

Possible values:

  • Absolute URL - the complete address of the page (such as href="http://www.example.com/formresult.asp")
  • Relative URL - points to a file within the current site (e.g., href="formresult.asp")

Technical Details

Return Value: String value indicating the URL to which form data will be sent.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support

Related Pages

HTML Reference Manual:HTML <button> formaction Attribute