How to Create Show Password Feature / Toggle Password Visibility using JavaScript

How to Create Show Password Feature / Toggle Password Visibility using JavaScript

Step 1) Add HTML:
<p>Click the radio button to show and hide password:</p>

Password: <input type="password" value="test123" id="myInput"><br><br>
<input type="checkbox" onclick="myFunction()">Show Password
Step 2) Add JavaScript:
<script>
function myFunction() {
  var x = document.getElementById("myInput");
  if (x.type === "password") {
    x.type = "text";
  } else {
    x.type = "password";
  }
}
</script>

Final output

How to Create Show Password Feature / Toggle Password Visibility using JavaScript
You may Also Like
Scroll to top