-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
35 lines (33 loc) · 1.22 KB
/
scripts.js
File metadata and controls
35 lines (33 loc) · 1.22 KB
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
const password = document.getElementById('password');
const confirmPass = document.getElementById('confirmPass');
const errorClass = document.querySelectorAll('.error');
const subButton = document.querySelector('.btn');
const confirmLabel = document.querySelector('.confirmLabel');
const passwordLabel = document.querySelector('.passwordLabel');
const passAlert =
'Passwords do not match. Please check your spelling and try again';
let pass = '';
let confPass = '';
function comparePass(x, y) {
if (x !== y || x === '' || y === '' || (x === '' && y === '')) {
confirmLabel.innerHTML =
'CONFIRM PASSWORD <span class=invalid>✗</span>';
passwordLabel.innerHTML = 'PASSWORD <span class=invalid>✗</span>';
errorClass.forEach((pass) => {
pass.classList.add('error');
});
} else {
confirmLabel.innerHTML =
'CONFIRM PASSWORD <span class=valid>✔</span>';
passwordLabel.innerHTML = 'PASSWORD <span class=valid>✔</span>';
subButton.disabled = false;
errorClass.forEach((pass) => {
pass.classList.remove('error');
});
}
}
password.addEventListener('input', () => (pass = password.value));
confirmPass.addEventListener('input', () => {
confPass = confirmPass.value;
comparePass(pass, confPass);
});