Javascript DOM HTML Input Password value Property set

Introduction

Change the value of the password field:

document.getElementById("myPsw").value = "NewPassword123";

View in separate window

<!DOCTYPE html>
<html>
<body>

<form>
Password: <input type="password" id="myPsw">
</form><p id="demo"></p>
<button onclick="display()">Display value</button>
<button onclick="change()">Change value</button>

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

function change() {//from  w  ww . j  a v a 2s  .c o m
  var x = document.getElementById("myPsw").value = "NewPassword123";
  document.getElementById("demo").innerHTML = "The value was changed to: " + x;
}
</script>

</body>
</html>



PreviousNext

Related