-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriptContact.js
74 lines (63 loc) · 2.86 KB
/
scriptContact.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
// HAMBURGER MENU
/* On the hamburger/nav button
- on click, show the slide-out menu
- on click, hide the hamburger button (class navButton) */
/* On the X button on the slide-out nav
- on click, hide the slide-out menu
- on click, hide the class of hamburger menu */
// Selecting Elements
const hamElement = document.querySelector(".navButton");
const slideOutMenu = document.querySelector(".slideOutNav");
const hamCloseButton = document.querySelector(".xButton");
// On click, open slide-out nav and remove hamburger icon
hamElement.addEventListener("click", () => {
slideOutMenu.classList.add("slideOutNavOpen");
// hamElement.style.display = "none";
// *COME BACK TO THIS. Not sure how to remove and put back hamElement and when not clicking on one of the links but when the XButton is clicked, and when window is resized, the hamElement doesn't go away.
/* personal note:
what I target.object.method (add is exclusive to the classList). Classlist specifies that this is a class so you don't need the dot! */
})
// On click, close slide-out nav and show hamburger icon
hamCloseButton.addEventListener("click", () => {
slideOutMenu.classList.remove("slideOutNavOpen");
// hamElement.style.display = "block";
})
// CONTACT FORM
/* Upon submission of form (conditional - content should not be blank):
- remove the contact form
- replace with confirmation message on screen (create)
- clear original values entered
- create refresh button to return to original page
*/
// Selecting Elements
const submitForm = document.querySelector(".sendForm");
const nameElement = document.querySelector("input");
const emailElement = document.querySelector("input#email");
const messageElement = document.querySelector("textarea");
const contactForm = document.querySelector(".myForm");
const refreshButton = document.querySelector(".refreshButton");
// Function for contact form
contactForm.addEventListener("submit", (event) => {
event.preventDefault();
if (contactForm !== '') {
// Create div & h2 submission confirmation message
let div = document.createElement('div');
div.id = 'newText';
div.className = 'new';
let h2 = document.createElement('h2');
const fullName = nameElement.value;
// ^why doesn't this work when outside of the function?
h2.textContent = `Thank you, ${fullName}! We will respond to your message within the next 1-2 business days.`;
div.appendChild(h2);
const removedForm = document.querySelector(".fillForm");
removedForm.appendChild(div);
// Clear values
nameElement.value = "";
emailElement.value = "";
messageElement.value = "",
// Remove contact form elements
contactForm.style.display = "none";
// Refresh Button
refreshButton.style.display = "block";
}
})