Open In App

HTML DOM Input Image formTarget Property

Last Updated : 15 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML DOM Input Image formTarget Property is used to set or return the value of the formTarget of the Input Element having an image field. The Target attribute is used to specify whether the submitted result will open in the current window, a new tab or on a new frame. 

Syntax:

  • To return the formTarget Property.
imageObject.formTarget
  • To set the formTarget Property.
imageObject.formTarget = "_blank|_self|_parent|_top|framename"

Property Values: It accepts five parameters as mentioned and described below:

  • _blank: It defines that the submitted result will open in a new window or in a new tab.
  • _self: It is the default value. It specifies that the submitted result will be open in the same window.
  • _parent: It specifies that the result will be open in a parent frameset.
  • _top: It specifies that the result will open in the full body of the window.
  • framename: It opens the response in a named frame.

Return Value: It returns a string value that represents whether the submitted result will open in the current window, a new tab or on a new frame. 

Example 1: This example illustrates how to return Input Image for the target property. 

HTML




<!DOCTYPE html>
<html>
   
<head>
    <title>
        HTML DOM Input Image formTarget Property
    </title>
</head>
 
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
    <h2>
        DOM Input Image formTarget Property
    </h2>
    <button onclick="my_geek()">
        <input id="myImage"
               name="myGeeks"
               type="image"
               src=
               alt="Submit"
               formaction="#" a
               formtarget="_blank"
               formenctype="text/plain"
               width="48" height="48">
    </button>
    <h2 id="Geek_h" style="color:green;"></h2>
   
    <script>
        function my_geek() {
 
            // Return Input Image formTarget Property.
            let txt = document.getElementById(
                "myImage").formTarget;
            document.getElementById("Geek_h").innerHTML = txt;
        }
    </script>
</body>
 
</html>


Output:

 

 Example 2: This Example illustrates how to set the Property. 

HTML




<!DOCTYPE html>
<html>
   
<head>
    <title>
        HTML DOM Input Image formTarget Property
    </title>
</head>
 
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
    <h4>
        DOM Input Image formTarget Property
    </h4>
    <button onclick="my_geek()">
        <input id="myImage" name="myGeeks"
               type="image"
               src=
               alt="Submit"
               formaction="#" a
               formtarget="_blank"
               formenctype="text/plain"
               width="48" height="48">
    </button>
    <h2 id="Geek_h" style="color:green;">
    </h2>
   
    <script>
        function my_geek() {
            // change Input Image formTarget Property.
            let txt = document.getElementById(
                "myImage").formTarget = "_self";
            document.getElementById("Geek_h").innerHTML =
                "The formTarget as changed to " + txt;
        }
    </script>
</body>
 
</html>


Output:

 

 Supported Browsers: The browsers supported by HTML DOM Input Image formTarget Property are listed below:

  • Google Chrome 
  • Edge 12+
  • Firefox 
  • Opera 
  • Safari 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads