Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM Form target Property

  • Last Updated : 22 Jul, 2019

The DOM Form Target property is used to set or return the value of the target attribute of the form.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 target property.
    formObject.target
  • It is used to set the target property.
    formObject.target = "_blank|_self|_parent|_top|framename"

    Property Values

    • _blank: It defines that submitted result will open in a new window or in a new tab.
    • _self: It specify that the submitted result will be open in a same window.
    • _parent: It specify 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 in a named frame.

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

    Example-1: HTML Program that illustrate how to set the Property.






    <!DOCTYPE html>
    <html>
      
    <head>
        <title>DOM Form target Property</title>
        <style>
            h1 {
                color: green;
            }
              
            body {
                text-align: center;
            }
        </style>
    </head>
      
    <body>
        <h1>GeeksforGeeks</h1>
        <h2>DOM Form target Property</h2>
        <form action="#" id="GFG" target="_self">
            First name:
            <input type="text" name="fname">
            <br> Last name:
            <input type="text" name="lname">
            <br> Address:
            <input type="text" name="Address">
            <br>
            <input type="submit" value="Submit">
        </form>
        <BR>
        <b><p>Click on Try it Button to set the
          value of the target attribute.</p>     
            
            <button onclick="Geeks()">Try it</button>
            <p id="sudo" 
               style="color:green;fonnt-size:20px;">
          </p>
            
            <script>
                function Geeks()  {
              // Set _blank property.
            var x = document.getElementById(
              "GFG").target = "_blank";
           document.getElementById("sudo").innerHTML = 
             "The value of the target attribute was changed to" 
           + x;
                }
            </script>
        </body>
    </html>

    Output:

    Before Clicking On Button:

    After Clicking On Button:

    Example-2: HTML Program that illustrate how to return the property.




    <!DOCTYPE html>
    <html>
      
    <head>
        <title>DOM Form target Property</title>
        <style>
            h1 {
                color: green;
            }
              
            body {
                text-align: center;
            }
        </style>
    </head>
      
    <body>
        <h1>GeeksforGeeks</h1>
        <h2>DOM Form target Property</h2>
        <form action="#" 
              id="GFG" 
              target="_self">
            First name:
            
            <input type="text" 
                   name="fname">
            <br> Last name:
            
            <input type="text" 
                   name="lname">
            <br> Address:
            
            <input type="text" 
                   name="Address">
            <br>
            
            <input type="submit" 
                   value="Submit">
        </form>
        <BR>
        
      <b><p>Click on Try it Button to return 
        the value of the target attribute.</p></b>
        
            <button onclick="Geeks()">Try it</button>
            <p id="sudo" style="color:green;font-size:30px;">
      </p>
            <script>
                function Geeks()  {
                    
                // Return form target property.
            var x = document.getElementById("GFG").target;
           document.getElementById("sudo").innerHTML = x;
                }
            </script>
        </body
    </html>

    Output:

    Before Clicking On Button:

    After Clicking On Button:

    Supported Browsers:

    • Google Chrome
    • Mozilla Firefox
    • Edge
    • Safari
    • Opera

    Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.




    My Personal Notes arrow_drop_up
Recommended Articles
Page :