Button formTarget attribute
Definition and usage
formTarget
Attribute 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 form's 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;
Example 2
Change the value of the button's formtarget attribute:
document.getElementById("myBtn").formTarget = "_self";
Example 3
Another example of returning the formTargert attribute:
var x = document.getElementById("myBtn").formTarget;
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