Form target Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form

Description

The target property sets or gets the target attribute in a form, which indicates where to display the response received after submitting the form.

Set the target property with the following Values

Value Description
_blankOpens in a new window
_self Opens in the same frame as it was clicked (default)
_parent Opens in the parent frameset
_top Opens in the full body of the window
framename Opens in a named frame

Return Value

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

The following code shows how to change where to display the response that is received after submitting a form:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm" action="#">
  First name: <input type="text" name="fname" value="Donald"><br>
  Last name: <input type="text" name="lname" value="Duck"><br>
  <input type="submit" value="Submit">
</form>//  w  w  w .  jav  a2s . com

<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>

Related Tutorials