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
1 2 |
Password: <input type="password" value="Password" id="myInput"><br><br> <input type="checkbox" onclick="myFunction()">Show Password |
Javascript for Show and Hide for password
1 2 3 4 5 6 7 8 9 10 11 |
<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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<!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> |