Javascript DOM HTML Form target Property

Introduction

Change where to display the response received after submitting a form:

document.getElementById("myForm").target = "_blank";

Click button to set the value of the target attribute in the form to "_blank".

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm" action="/action_page.php">
  First name: <input type="text" name="fname" value="CSS"><br>
  Last name: <input type="text" name="lname" value="HTML"><br>
  <input type="submit" value="Submit">
</form>//from ww w  . java 2 s .co m
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  document.getElementById("myForm").target = "_blank";
  document.getElementById("demo").innerHTML = "The value of the target attribute was changed.";
}
</script>

</body>
</html>

The target property sets or gets the value of the target attribute in a form.

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

Property Values

Value Description
_blankOpens in a new window
_self Opens in the same frame as it was clicked. Default
_parent Opens in the parent frame set
_top Opens in the full body of the window
framename Opens in a named frame

The target property returns a String representing where to display the response that is received after submitting the form.




PreviousNext

Related