Computer >> Computer tutorials >  >> Programming >> HTML

How to use formtarget attribute in HTML?


The formtarget attribute in HTML is used to indicate where the response that is received after the form submission is displayed. It overrides the target attribute of the HTML form tag. Use the formtarget attribute only with input type submit an image.

Here are the attribute values of the formtarget attribute −

S. NoValueDescription
1_blankResponse gets displayed in a new window or tab
2_selfThe default value. The response gets displayed in the same frame.
3_parentResponse gets displayed in the parent frame
4_topResponse gets displayed in the full body of the window
5
framename
Response gets displayed in a named iframe


How to use formtarget attribute in HTML?

Example

You can try to run the following code to learn how to use the formtarget attribute in HTML.

<!DOCTYPE html>
<html>
   <head>
      <title>HTML formtarget attribute</title>
   </head>
   <body>
      <form action = ”/new.php” method = "get">
         Student Name<br><input type = "text" name = "name"/><br>
         Student Subject<br><input type = "text" name = "subject"/><br>
         <input type = "submit" value = "Submit">
         <input type = "submit" formtarget = "_blank" value="Submit (new window)">
      </form>
   </body>
</html>