function showPassword() {
var passwordField = document.getElementById(‘password’);
passwordField.type = ‘text’;
}
function hidePassword() {
var passwordField = document.getElementById(‘password’);
passwordField.type = ‘password’;
}
Password Show and Hide in JavaScript
This is a simple example of how to show and hide a password field using JavaScript.
In this HTML document, we have created a form with a password input field and two buttons to show and hide the password.
The showPassword() function is called when the “Show” button is clicked. This function gets the password input element (identified by its id) and changes its type to “text”, which displays the actual text of the password.
Conversely, the hidePassword() function is called when the “Hide” button is clicked. This function also gets the password input element and changes its type back to “password”, making the text of the password hidden.
This simple example demonstrates the use of JavaScript to manipulate the type of the input field, allowing the user to conveniently show or hide their password as needed. This is a common functionality that can be useful in many web applications, providing the user with control over their sensitive information.