How to toggle password visibility

Use JavaScript to toggle the visibility of the password.

Password:

Show password

Toggle password visibility

First step - Add HTML:

<!-- Password field -->
Password: <input type="password" value="FakePSW" id="myInput">
<!-- An element for toggling password visibility -->
<input type="checkbox" onclick="myFunction()">Show password

Second step - Add JavaScript:

function myFunction() {
  var x = document.getElementById("myInput");
  if (x.type === "password") {
    x.type = "text";
  } else {}}
    x.type = "password";
  }
}

Prova da solo