Javascript DOM HTML Input Submit formTarget Property set

Introduction

Change the value of the formtarget attribute of a submit button:

document.getElementById("mySubmit").formTarget = "_self";

This example contains a form with a submit button that submits the form to a new window:

Click on button to change the value of the formtarget attribute of the submit button.

View in separate window

<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php" method="get">
  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  w w.  j a va 2s . c o  m*/
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  document.getElementById("mySubmit").formTarget = "_self";
  document.getElementById("demo").innerHTML = "The value of the formtarget attribute was changed from '_blank' to '_self'.";
}
</script>

</body>
</html>



PreviousNext

Related