Add Toggle Multiple Form Visibility project

This commit is contained in:
Andrea Fazzi 2024-07-16 07:36:08 +02:00
parent 5f215211bb
commit 6c259f456f
4 changed files with 92 additions and 0 deletions

View file

@ -11,6 +11,7 @@ func main() {
mux.Handle("GET /toggle-password-visibility/", http.StripPrefix("/toggle-password-visibility", http.FileServer(http.Dir("toggle-password-visibility"))))
mux.Handle("GET /toggle-multiple-fields/", http.StripPrefix("/toggle-multiple-fields", http.FileServer(http.Dir("toggle-multiple-fields"))))
mux.Handle("GET /toggle-multiple-forms/", http.StripPrefix("/toggle-multiple-forms", http.FileServer(http.Dir("toggle-multiple-forms"))))
log.Println("Start the web server...")
err := http.ListenAndServe(":8080", mux)

View file

@ -0,0 +1,7 @@
# Toggle Multiple Password Fields
A script that let's users toggle the visibility with the ability to toggle multiple fields.
# Reference
* https://leanwebclub.com/learn/js-essentials/project-toggle-multiple-password-fields/

View file

@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css">
<title>Toggle Multiple Forms Password Visibility</title>
</head>
<body>
<h1>Toggle Multiple Forms Password Visibility</h1>
<h2>Change Username</h2>
<p>Enter your username and password to change your username.</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-password" id="show-password">
Show password
</label>
</div>
<p>
<button type="submit">Change Username</button>
</p>
</form>
<h2>Change Password</h2>
<p>Enter your current password and new password below.</p>
<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 src="script.js"></script>
</body>
</html>

View file

@ -0,0 +1,19 @@
let passwordFields = document.querySelectorAll('input[type="password"]');
let checkboxes = document.querySelectorAll('input[type="checkbox"]');
let state = {true: "text", false: "password" };
window.addEventListener('click', function (event) {
if (event.target.matches('#show-password')) {
for (let field of passwordFields) {
field.type=state[event.target.checked];
}
}
else {
console.log("Show passwords toggle");
for (let field of passwordFields) {
field.type=state[event.target.checked];
}
}
});