-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.js
92 lines (75 loc) · 2.83 KB
/
contact.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//function to toggle to contact pop up
/*let popUp_container = document.getElementById("container");
let popUp_overlay_container = document.getElementById("overlayCon");
let popUp_overlayBTN = document.querySelector(".overlayBtn");
popUp_overlayBTN.addEventListener('click', ()=> {
popUp_container.classList.toggle('right-panel-active');
})*/
const form = document.getElementById('form');
const messengerName = document.getElementById('name');
const email = document.getElementById('email');
const subjectLine = document.getElementById('subjectLine');
const message = document.getElementById('message');
const name_error = document.getElementById('name_error');
const email_error = document.getElementById('email_error');
const subjectLine_error = document.getElementById('subjectLine_error');
const message_error = document.getElementById('message_error');
const successfulFormPopup = document.getElementById('successful-form-popup')
form.addEventListener('submit',(e) => {
let emailStatus = true;
if (emailStatus) {
if (messengerName.value === '' || messengerName.value === null) {
e.preventDefault();
name_error.innerHTML = "Name is required";
emailStatus = false;
//do not show line label
document.querySelector('#lineLabel').style.backgroundColor = 'white';
}else {
name_error.innerHTML = "";
}
const emailRegex = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if (!email.value.match(emailRegex)) {
e.preventDefault();
email_error.innerHTML = "A valid email is required";
emailStatus = false;
//do not show line label
document.querySelector('#lineLabel2').style.backgroundColor = 'white';
}else {
email_error.innerHTML = "";
}
if (subjectLine.value === '' || subjectLine.value === null) {
e.preventDefault();
subjectLine_error.innerHTML = "A descriptive subject line is required";
emailStatus = false;
//do not show line label
document.querySelector('#lineLabel3').style.backgroundColor = 'white';
}else {
subjectLine_error.innerHTML = "";
}
if (message.value === '' || message.value === null) {
e.preventDefault();
message_error.innerHTML = "A message is required";
emailStatus = false;
}else {
message_error.innerHTML = "";
}
}
//Display the success message
if (emailStatus) {
form.style.display = "none";
successfulFormPopup.style.display = "block";
e.preventDefault();
}
})
const sendAnotherEmail = document.getElementById('sendAnotherEmail');
sendAnotherEmail.addEventListener('click', () => {
//clear the form
messengerName.value = "";
email.value = "";
subjectLine.value = "";
message.value = "";
//display the clear form
form.style.display = "block";
successfulFormPopup.style.display = "none";
});
// do not show the