Return where to display the response after submitting a form:
var x = document.getElementById("myBtn").formTarget;
Click the button to return the value of the formtarget attribute of the submit button above.
<!DOCTYPE html> <html> <body> <form action="/action_page.php" method="get" target="_self"> First name: <input type="text" name="fname" value="CSS"><br> Last name: <input type="text" name="lname" value="HTML"><br> <button id="myBtn" type="submit" formtarget="_blank">Submit to a new window</button> </form>//from ww w . j a va2s. c o m <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myBtn").formTarget; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The formTarget property sets or gets the value of the formtarget attribute of a button.
The formtarget attribute sets where to display the response after submitting the form.
This attribute overrides the form's target attribute.
The formtarget attribute is only used for buttons with type="submit".
Property Values
Value | Description |
---|---|
_blank | Loads the response in a new window/tab |
_self | Default. Loads the response in the same frame |
_parent | Loads the response in the parent frame |
_top | Loads the response in the full body of the window |
framename | Loads the response in a named iframe |
The formTarget property returns a String representing where to display the response after submitting the form.