Open In App

HTML DOM Button formTarget Property

The Button formTarget property in HTML DOM is used to set or return the value of the formTarget attribute of a button. After submission of the form, the formTarget attribute is called. The form data is to be sent to the server after submission of the form. 

Syntax:



buttonObject.formTarget
buttonObject.formTarget = "_blank | _parent | _self | _top | framename"

Property Values:

Return Value: It returns a string value which represent the place where the response has to be submitted. 



Example: This example describes how to set and get the value of formTarget property. 




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Button formTarget Property
    </title>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
 
    <h2>DOM Button formTarget Property</h2>
 
    <form action="/gfg.php"
          method="post" id="users">
 
        <label for="username">Username:</label>
        <input type="text" name="username" id="Username">
 
        <br><br>
 
        <label for="password">
          Password :
        </label>
        <input type="password" name="password">
 
        <button id="btn" type="submit" formtarget="_blank">
            Load Changed formAction value
        </button>
    </form>
 
    <br>
 
    <button onclick="myGeeks()">
        Submit
    </button>
 
    <p id="GFG"></p>
 
    <!-- script to set and get the value of formTarget attribute -->
    <script>
        function myGeeks() {
            let x = document.getElementById("btn").formTarget;
            let y = document.getElementById("btn").formTarget = "_self";
            document.getElementById("GFG").innerHTML
                = "formTarget changed to " + y + "<br> from " + x;
        }
    </script>
</body>
 
</html>

Output: 

 

Supported Browsers:


Article Tags :