Input Submit formTarget Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Submit

Description

The formTarget property sets or gets the formtarget attribute of a submit button, which controls where to display the response that is received after submitting the form.

The formtarget attribute overrides the target attribute of the <form> element.

Set the formTarget property with the following Values

Value Description
_blankThe response is displayed in a new window/tab
_self The response is displayed in the same frame (this is default)
_parent The response is displayed in the parent frame
_top The response is displayed in the full body of the window
framename The response is displayed in a named iframe

Return Value

A String, representing where to display the response after submitting the form

The following code shows how to check where the response will be displayed after submitting a form:

Demo Code

ResultView the demo in separate window

<!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>
  <input type="submit" id="mySubmit" value="Submit" formtarget="_blank">
</form>/*from w w w .j av  a  2s  .  co  m*/

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var v = document.getElementById("mySubmit").formTarget;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials