HTML input Tag formtarget Attribute Tutorial

In this section, we will learn what the formtarget attribute is and how to use it.

What is formtarget Attribute in HTML <input> Tag?

After submitting a form data (by clicking the submit button) to a server, the server usually sends back a response to specify if the operation was a success or a failure.

Via the formtarget attribute, we can declare where this response should be displayed in!

For example, one of the values we could use for the formtarget attribute is “_blank”. This value means display the response from the server in a new browser tab or window without closing the current document.

Note: the HTML <form> element has an attribute called “target” which is used for the same purpose as the formtarget. But if we used both attributes in a form, the value of the formtarget attribute will override the value of the target attribute.

HTML formtarget Attribute in <input> Tag Syntax:

<input type = “image | submit” formtarget = “value” >

<input> Tag formtarget Attribute Values

The values we can use for the formtarget attribute are:

Name

Description

_blank

Open the linked document on a new tab or window.

_self

Open the linked document on the window of the current document.

_parent

Open the linked document on the parent frame

_top

Open the linked document on the full body of the window

framename

Open the linked document on the specified iframe.

Example: using formtarget attribute in HTML <input> tag

See the Pen using formtarget attribute in HTML <input> tag by Omid Dehghan (@odehghan) on CodePen.

For this particular example, after submitting the form data, the server’s response will be displayed on a new browser window or tab.

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies