-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvanilla-2.html
64 lines (58 loc) · 1.48 KB
/
vanilla-2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Vanilla js project 2</title>
</head>
<body>
<!-- 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. -->
<form>
<div>
<label for="current-password">Current Password</label>
<input type="password" name="current-password" id="current-password">
</div>
<div>
<label for="new-password">New Password</label>
<input type="password" name="new-password" id="new-password">
</div>
<div>
<label for="show-passwords">
<input type="checkbox" name="show-passwords" id="show-passwords">
Show passwords
</label>
</div>
<p>
<button type="submit">Change Passwords</button>
</p>
</form>
<script>
// 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';
return;
}
var maskText = function (input) {
input.type = 'password';
return;
}
// add evenlistener and loop inputs when clicked
check.addEventListener('click', function(event){
if (event.target.checked === true) {
passwords.forEach(function(item, index){
showText(item);
});
}
else {
passwords.forEach(function(item, index){
maskText(item);
});
}
});
</script>
</body>
</html>