Javascript DOM HTML Form target Property get

Introduction

Return the value of the target attribute in a form:

var x = document.getElementById("myForm").target;

Click button to return the value of the target attribute in the form.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm" action="/action_page.php" 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" value="Submit">
</form>/*from  w w w .  j  a  v  a  2s .  c  o m*/
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementById("myForm").target;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related