Goal
Modify the previous script to support multiple forms, ensuring each checkbox only toggles fields in its own form.
Project
Change Username
Enter your username and password to change your username.
Change Password
Enter your current password and new password below.
View Source
(function() {
let elPassword = document.querySelector( "#password" );
let elPasswords = document.querySelectorAll( "#current-password, #new-password" );
document.addEventListener( "input", e =>
{
if( e.target.id === "show-password" )
{
let inputType = e.target.checked ? "text" : "password";
elPassword.setAttribute( "type", inputType );
}
if( e.target.id === "show-passwords" )
{
let inputType = e.target.checked ? "text" : "password";
elPasswords.forEach( elPassword => elPassword.setAttribute( "type", inputType ) );
}
});
})();
Projects
- Toggle Password Visibility
- Toggle Multiple Password Fields
- Toggle Passwords in Multiple Forms
- Character Count
- Character and Word Count
- Announcing the Count
- Random Ron
- Random Ron Without Duplicates
- New York Times Top Stories
- New York Times Multiple Categories
- Sanitizing the NYT API Data
- Monster Shuffle