Skip to content
Related Articles
Open in App
Not now

Related Articles

HTML | DOM Input Submit formTarget Property

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 26 Aug, 2022
Improve Article
Save Article

The Input Submit formTarget Property in HTML DOM is used to set or return the value of the formtarget attribute of the submit 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: 

  • It is used to return the formTarget property.
submitObject.formTarget
  • It is used to set the formTarget property.
submitObject.formTarget = "_blank|_self|_parent|_top|framename"

Property Values:

  • _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 a same window.
  • _parent: It specifies that the result will be open in a parent frameset.
  • _top: It specify that the result will open in a full body of the window.
  • framename: It opens the response in a named frame.

Return Value: It returns a string value which 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 Submit formTarget property. 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOM Input Submit formTarget Property
    </title>
</head>
<body style="text-align:center;">
    <h1>
        GeeksForGeeks
    </h1>
    <h2>
        HTML DOM Input Submit formtarget Property
    </h2>
    <form action="#" method="get" target="_self">
        <input type = "submit" id = "Geeks" name="myGeeks"
            value = "Submit @ geeksforgeeks" formTarget="_blank">
    </form>
    <p>
        click on below button to return the Property
    </p>
    <button onclick = "myGeeks()">
        Click Here!
    </button>
    <p id = "GFG"style="font-size:25px;"></p>
     
    <!-- Script to return submit formTarget Property -->
    <script>
        function myGeeks() {
            var btn = document.getElementById("Geeks").formTarget;
            document.getElementById("GFG").innerHTML = btn;
        }
    </script>
</body>
</html>

Output: 

Before Clicking the Button:

  

After Clicking the Button:

  

Example 2: This example illustrates how to set Input Submit formTarget Property. 

HTML




<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOM Input Submit formTarget Property
    </title>
</head>
<body style="text-align:center;">
    <h1>
        GeeksForGeeks
    </h1>
    <h2>
        HTML DOM Input Submit formtarget Property
    </h2>
    <form action="#" method="get" target="_self">
        <input type = "submit" id = "Geeks" name="myGeeks"
        value = "Submit @ geeksforgeeks" formTarget="_blank">
    </form>
    <p>
        click on below button to set the Property
    </p>
    <button onclick = "myGeeks()">
        Click Here!
    </button>
    <p id = "GFG"style="font-size:23px;"></p>
     
    <!-- Script to set submit formTarget Property -->
    <script>
        function myGeeks() {
            var btn = document.getElementById("Geeks").formTarget
                    = "_self";
                     
            document.getElementById("GFG").innerHTML
                    = "The value of the Formtarget attribute"
                      + " was changed to " + btn;
        }
    </script>
</body>
</html>

Output: 

Before Clicking the Button:

  

After Clicking the Button: 

 

Supported Browsers: The browser supported by DOM input submit formTarget property are listed below:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Opera
  • Safari 1 and above

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!