Javascript DOM HTML Input Password name Property set

Introduction

Change the name of a password field:

document.getElementById("myPsw").name = "newPasswordName";

Click the buttons to display and change the value of the name attribute of the password field.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form>
Password: <input type="password" id="myPsw" name="pw">
</form>/*from   w  w  w  .jav a 2 s.co m*/
<p id="demo"></p>
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>

<script>
function display() {
  var x = document.getElementById("myPsw").name;
  document.getElementById("demo").innerHTML = "The name of the password field is: " + x;
}

function change() {
  var x = document.getElementById("myPsw").name = "newPasswordName";
  document.getElementById("demo").innerHTML = "The name was changed to: " + x;
}
</script>

</body>
</html>



PreviousNext

Related