Button formTarget attribute

Definition and usage

formTarget Sets or returns the button's formtarget attribute value.

The formtarget attribute specifies where the response is displayed after the form is submitted. This attribute overrides the target attribute.

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

Note:formtarget attribute It is a new attribute of the <button> element in HTML5.

Instance

Example 1

After submitting the form, return to the location where the response is displayed:

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

Try it yourself

Example 2

Change the value of the button's formtarget attribute:

document.getElementById("myBtn").formTarget = "_self";

Try it yourself

Example 3

Another example of returning the formTargert attribute:

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

Try it yourself

Syntax

Return the formTarget attribute:

buttonObject.formTarget

Set the formTarget attribute:

buttonObject.formTarget = "_blank|_self|_parent|_top|framename"

Attribute value

Value Description
_blank Load the response in a new window/tab.
_self Load the response in the same frame (default).
_parent Load the response in the parent frame.
_top Load the response in the entire window.
framename Load the response in the named iframe.

Technical Details

Return Value: A string value indicating where the response is displayed after the form is submitted.

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> formtarget Attribute