-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
50 lines (40 loc) · 1.36 KB
/
script.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
37
38
39
40
41
42
43
44
45
46
47
48
49
const formHero = document.querySelector('.form_hero');
const formBottom = document.querySelector('.form_bottom');
const emailHero = document.querySelector('.form_hero #email');
// const emailBottom = document.querySelector('.form_bottom #email');
const errormsg = document.querySelector('.error_text');
const toastmsg = document.querySelector('.toast_success');
// const toastmsgb = document.querySelector('.toast_success_bottom');
emailHero.addEventListener('input', activeValidation);
// emailBottom.addEventListener('input', activeValidation);
formHero.addEventListener('submit',formValidation);
formBottom.addEventListener('submit', formValidation);
function activeValidation(e) {
if(email.validity.valid) {
form.classList.remove('error');
} else {
validationError();
}
}
// FORM VALID SUBMISSION CHECK
function formValidation(e) {
e.preventDefault();
if(!email.validity.valid){
validationError();
} else {
toastmsg.classList.add('show');
setTimeout(function() {
toastmsg.classList.remove('show');
}, 3000)
}
}
// ERROR MESSAGES
function validationError() {
if(email.validity.patternMismatch){
errormsg.textContent = "Oops! Please check your email";
form.classList.add('error');
} else if (email.validity.valueMissing){
errormsg.textContent = "Oops! Please add your email";
form.classList.add('error');
}
}