The formTarget
property sets or gets the formtarget attribute of a submit button.
The formtarget
attribute indicates where
to display the response that is received after submitting the form.
The formtarget
attribute from submit element
overrides the target attribute of the <form> element.
formTarget |
Yes | 10.0 | Yes | Yes | Yes |
Return the formTarget property.
var v = submitObject.formTarget
Set the formTarget property.
submitObject.formTarget='_blank|_self|_parent|_top|framename'
Value | Description |
---|---|
_blank | Display response in a new window/tab |
_self | Display response in the same frame. This is default |
_parent | Display response in the parent frame |
_top | Display response in the full body of the window |
framename | Display response in a named iframe |
A String type value representing where to display the response after submitting the form.
The following code shows how to change the value of the formtarget attribute of a submit button.
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp" method="get">
First name: <input type="text" name="fname" value="abc"><br>
<input type="submit" id="mySubmit" value="Submit" formtarget="_blank">
</form><!--from w w w.jav a 2s .c o m-->
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("mySubmit").formTarget = "_self";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get where the response will be displayed after submitting a form.
<!DOCTYPE html>
<html>
<body>
<!-- w w w . ja va 2 s. c o m-->
<form action="demo_form.asp" method="get" target="_self">
First name: <input type="text" name="fname" value="abc"><br>
<input type="submit" id="mySubmit" value="Submit" formtarget="_blank">
</form>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("mySubmit").formTarget;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: