Show and hide password using JavaScript
While filling up a form, there comes a situation where we type a password and want to see what we have typed till now. To see that, there is a checkbox clicking on which makes the characters visible.
In this post, this feature i.e. toggling password is implemented using JavaScript.
Algorithm
1)Create a HTML form which contain an input field of type password.2)Create a checkbox which will be responsible for toggling.
3)Create a function which will response for toggling when a user clicks on the checkbox.
Examples:
Password is geeksforgeeks.
So, on typing it will show like this *************
And on clicking the checkbox it will show the characters: geeksforgeeks.
<!DOCTYPE html> <html> <body> <b><p>Click on the checkbox to show or hide password: </p></b> <b>Password</b>: <input type="password" value="geeksforgeeks" id="typepass"> <input type="checkbox" onclick="Toggle()"> <b>Show Password</b> <script> // Change the type of input to password or text function Toggle() { var temp = document.getElementById("typepass"); if (temp.type === "password") { temp.type = "text"; } else { temp.type = "password"; } } </script> </body> </html> |
Output:
-
Hide password:

-
Show password:

Recommended Posts:
- Hide or show HTML elements using visibility property in JavaScript
- How to Show and Hide div elements using Checkboxes ?
- How to Show and Hide div elements using radio buttons?
- How to display icon next to show/hide text on button?
- Hide or show elements in HTML using display property
- How to hide or show one record from an ng-repeat within a table based on ng-click?
- jQuery | Hide/Show, Toggle and Fading methods with Examples
- Hide the cursor in a webpage using CSS and JavaScript
- How to hide Bootstrap modal with JavaScript?
- Password Matching using JavaScript
- Validate a password using HTML and JavaScript
- JavaScript | Program to generate one-time password (OTP)
- p5.js | show() Function
- AngularJS | ng-show Directive
- p5.js | hide() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


