-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (49 loc) · 1.71 KB
/
index.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
50
51
52
53
54
55
56
57
58
function validateEmail(email) {
const re = /\S+@\S+\.\S+/;
return re.test(email);
}
function displayError() {
document.querySelector('.email__error').classList.add("error");
document.querySelector('.email__error').classList.remove("hidden");
document.querySelector('.input').classList.add("error");
}
function removeError() {
document.querySelector('.email__error').classList.remove("error");
document.querySelector('.email__error').classList.add("hidden");
document.querySelector('.input').classList.remove("error");
}
function showSuccess() {
document.querySelector('.signup').classList.add("hidden");
document.querySelector('.success').classList.remove("hidden");
}
function hideSuccess() {
document.querySelector('.signup').classList.remove("hidden");
document.querySelector('.success').classList.add("hidden");
}
function subscribeClicked(event) {
event.preventDefault();
const email = document.querySelector('.input').value;
console.log(email);
if (validateEmail(email) == true) {
removeError();
showSuccess();
document.getElementById("success__email").innerHTML = email;
} else {
displayError();
}
}
function dismissClicked(event) {
hideSuccess();
document.querySelector('.signup__form').reset();
}
document.getElementById("signup__form").addEventListener("submit", subscribeClicked);
document.getElementById("signup__input").onblur = function () {
const email = document.querySelector('.input').value;
console.log(email);
if (validateEmail(email) == false) {
displayError();
} else {
removeError();
}
}
document.getElementById("dismiss__button").addEventListener("click", dismissClicked);