Javascript DOM HTML Form name Property set

Introduction

Change the name of a form:

document.getElementById("myForm").name = "newName";

Click button to change the value of the name attribute in the form element.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm" name="form1" 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>//w  w  w  .  j av  a 2  s  . co  m
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  document.getElementById("myForm").name = "newName";
  document.getElementById("demo").innerHTML = "The name of the form was changed.";
}
</script>

</body>
</html>



PreviousNext

Related