How to Show and Hide Password using JavaScript
In this tutorial, We will learn how to show and hide passwords using Javascript.
Create an HTML Form for Password
Password: <input type="password" value="Password" id="myInput"><br><br>
<input type="checkbox" onclick="myFunction()">Show Password
Javascript for Show and Hide for password
<script>
function myFunction() {
var x = document.getElementById("myInput");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</script>
Here is the full code is written in this tutorial
<!DOCTYPE html>
<html>
<body>
<p>Click the radio button to show the password</p>
Password: <input type="password" value="Password" id="myInput"><br><br>
<input type="checkbox" onclick="myFunction()">Show Password
<script>
function myFunction() {
var x = document.getElementById("myInput");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</script>
</body>
</html>
