HTML button Tag formaction Attribute Tutorial

In this section, we will learn what formaction attribute is and how it works.

What is formaction Attribute in HTML <button> Tag?

The formaction attribute is used to set the address of the linked form and send its data to that address when the button is clicked.

Note: if the target form has an address as well (the value set for the action attribute in that form is the address of the form), the value of the `formaction` attribute will override the value of the `action` attribute.

HTML formaction Attribute in <button> Tag Syntax:

<button formaction = "address"> </button>

<button> Tag formaction Attribute Values

The value we set for the formaction is the address (Relative or Absolute URL) in which we want to submit the data of the linked form to.

Example: using formaction attribute in HTML <button> tag

See the Pen using formaction attribute in HTML <button> tag by Omid Dehghan (@odchan1) on CodePen.

In this example, the <form> element has the attribute named `action` with the value “/signin”. By default, this would be the address to which the form data will be submitted to. But because the <button> element has the `formaction` attribute as well, the value of this attribute will override the value of the `action` attribute and so at the end for this particular example, the form data will be sent do “/signin2” address instead.

Leave a Reply