Summary -

In this topic, we described about the Formtarget with detailed example.

Formtarget used to override the target attribute of the <form> element. Formtarget used to specify where to display the form response.

We can use formtarget attribute with input types submit and the picture (type="submit" or type="image"). We can use formtarget attribute with input types submit and image.

The values can set to this attribute are _blank, _self, _parent or _top. formtarget attribute overrides the <form> target attribute. Once the form submitted, browser first checks for formtarget attribute and use the formtarget value if specified. If formtarget attribute not specified, it checks for <form> target attribute and uses the <form> target value if specified.

If both are specified, formtarget attribute value considered and <form> target attribute ignored.

Syntax -

<input type="submit" value="Submit" formtarget="_self">

Example -

Below example describes about how to formtrget attribute used with submit element.
<!DOCTYPE html>
<html>
  <body>
     <h2>The formtarget Attribute</h2>
      <form action="form-results.php">
         First name: <input type="text" name="fname"><br>
         Last name: <input type="text" name="lname"><br>
         <input type="submit" value="Submit as normal">
         <input type="submit" formtarget="_blank" value="Submit to 
                                                     a new window/tab"> 
      </form> 
  </body>
</html> 

Output -

First name:
Last name: