-
Notifications
You must be signed in to change notification settings - Fork 0
/
proj1-password-visibility.html
85 lines (66 loc) · 1.74 KB
/
proj1-password-visibility.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Password Visibility</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
body {
margin: 0 auto;
max-width: 40em;
width: 88%;
}
label {
display: block;
width: 100%;
}
input {
margin-bottom: 1em;
}
[type="checkbox"] {
margin-bottom: 0;
margin-right: 0.25em;
}
</style>
</head>
<body>
<h1>Password Visibility</h1>
<p>Enter your username and password to login.</p>
<form>
<div>
<label for="username">Username</label>
<input type="text" name="username" id="username">
</div>
<div>
<label for="password">Password</label>
<input type="password" name="password" id="password">
</div>
<div>
<label for="show-password">
<input type="checkbox" name="show-passwords" id="show-password">
Show password
</label>
</div>
<p>
<button type="submit">Log In</button>
</p>
</form>
<script>
// get the element
let showPasswordField = document.querySelector('#show-password');
let passwordField = document.querySelector('#password');
// listen for input
showPasswordField.addEventListener('change', function (event) {
let isPasswordShown = event.target.checked;
// if pass -> text, vice versa
if (isPasswordShown) {
// console.log("checkbox is checked");
passwordField.type = "text";
} else {
// console.log("checkbox is unchecked");
passwordField.type = "password";
}
});
</script>
</body>
</html>