Javascript DOM HTML Input Submit formTarget Property get

Introduction

Find out where the response will be displayed after submitting a form:

var x = document.getElementById("mySubmit").formTarget;

Click the button to display the value of the formtarget attribute of the submit button above.

View in separate window

<!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>
  <input type="submit" id="mySubmit" value="Submit" formtarget="_blank">
</form>/*w ww . j  a va2  s.co m*/
<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 formTarget property sets or gets the value of the formtarget attribute of a submit button.

The formtarget attribute specifies a name or a keyword that indicates where to display the response that is received after submitting the form.

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

Property 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

The formTarget property returns a String representing where to display the response after submitting the form.




PreviousNext

Related