-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
44 lines (36 loc) · 1.1 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
const form = document.querySelector('.cta_form');
const ctaEmail = document.querySelector('.cta_form #userEmail');
const errormsg = document.querySelector('.error_text');
const toastmsg = document.querySelector('.toast_success');
ctaEmail.addEventListener('input', activeValidation);
form.addEventListener('submit',formValidation);
function activeValidation(e) {
if(userEmail.validity.valid) {
form.classList.remove('error');
} else {
validationError();
}
}
// FORM VALID SUBMISSION CHECK
function formValidation(e) {
e.preventDefault();
if(!userEmail.validity.valid){
validationError();
} else {
console.log(toastmsg)
toastmsg.classList.add('show');
setTimeout(function() {
toastmsg.classList.remove('show');
}, 3000)
}
}
// ERROR MESSAGES
function validationError() {
if(userEmail.validity.patternMismatch){
errormsg.textContent = "Oops! That doesn’t look like an email address";
form.classList.add('error');
} else if (userEmail.validity.valueMissing){
errormsg.textContent = "Oops! Please add your email";
form.classList.add('error');
}
}