Skip to content

Instantly share code, notes, and snippets.

Last active October 14, 2020 18:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save eheiser/d2d755594b04f05b43045fbd1980ad17 to your computer and use it in GitHub Desktop.
Vanilla js day 3
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<title>Vanilla js project 2</title>
<!-- When a user clicks on the #show-passwords checkbox, it should show the text for the #current-password and #new-password fields if it’s checked, and mask it if it’s unchecked. -->
<label for="current-password">Current Password</label>
<input type="password" name="current-password" id="current-password">
<label for="new-password">New Password</label>
<input type="password" name="new-password" id="new-password">
<label for="show-passwords">
<input type="checkbox" name="show-passwords" id="show-passwords">
Show passwords
<button type="submit">Change Passwords</button>
// get my vars
var check = document.querySelector('#show-passwords');
var inputs = document.querySelectorAll('input[type ="password"]');
// make array from nodelist
let passwords = Array.from(inputs);
//define functions
var showText = function (input) {
input.type = 'text';
var maskText = function (input) {
input.type = 'password';
// add evenlistener and loop inputs when clicked
check.addEventListener('click', function(event){
if ( === true) {
passwords.forEach(function(item, index){
else {
passwords.forEach(function(item, index){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment