Javascript examples for DOM HTML Element:Button
The formTarget property sets or gets the formtarget attribute of a button, which 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".
Set the formTarget property with the following Values
Value | Description |
---|---|
_blank | display the response in a new window/tab |
_self | display the response in the same frame (this is default) |
_parent | display the response in the parent frame |
_top | display the response in the full body of the window |
framename | display the response in a named iframe |
A String, representing where to display the response after submitting the form
The following code shows how to return where to display the response after submitting a form:
<!DOCTYPE html> <html> <body> <form action="#" method="get"> First name: <input type="text" name="fname" value="Mary"><br> Last name: <input type="text" name="lname" value="Bond"><br> <button type="submit">Submit</button> <button id="myBtn" type="submit" formtarget="_blank">Submit to a new window/tab</button> </form>/*from w w w . j av a 2 s .co 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>