Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
54 lines (38 loc) · 1.36 KB
/
Copy pathscript.js
File metadata and controls
54 lines (38 loc) · 1.36 KB
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
//Hamburgur menu
const ul=document.getElementById('ul')
const menu=document.getElementById('toggle')
menu.addEventListener('click',()=>{
ul.classList.toggle('ulnewclass')
})
//collecting the form data and logging in the console
//select the form element
const form = document.querySelector(".contact-form");
//do the following on form submission
form.addEventListener('submit', event => {
event.preventDefault();
//extract the data on form submission
const nameInput = document.getElementById("name");
const emailInput = document.getElementById("email");
const phoneInput = document.getElementById("phone");
const instituteInput = document.getElementById("institution");
const messageInput = document.getElementById("message");
//making a formData object
const formData = {
name : nameInput.value,
email: emailInput.value,
phone: phoneInput.value,
institute: instituteInput.value,
message: messageInput.value
};
//logging the data
console.log(formData);
//we can now use fetchAPI to post data to the desired server
//we can also display successfull data sent message after a
//successfull post request
//reset the inputs
nameInput.value = "";
emailInput.value = "";
phoneInput.value = "";
instituteInput.value = "";
messageInput.value = "";
});