-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript.js
36 lines (28 loc) · 983 Bytes
/
javascript.js
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
const passwordNode = document.querySelector("#userPassword");
const confirmInput = document.querySelector("#passwordConfirm");
const confirmLabel = confirmInput.parentElement;
confirmInput.addEventListener("input", checkPasswords);
passwordNode.addEventListener("input", checkPasswords);
function checkPasswords(e) {
let pass1 = passwordNode.value;
let pass2 = confirmInput.value;
// prevents error messages when you just begin typing
if (pass2 === "") return;
if (pass2 !== pass1) {
confirmLabel.classList.add("passwordError")
}
else {
confirmLabel.classList.remove("passwordError")
confirmInput.setCustomValidity("");
}
}
const formNode = document.querySelector("form");
formNode.addEventListener("submit", (event) => {
let pass1 = passwordNode.value;
let pass2 = confirmInput.value;
if (pass1 !== pass2) {
confirmInput.setCustomValidity("Passwords need to match");
confirmInput.reportValidity();
event.preventDefault();
}
})