-
Notifications
You must be signed in to change notification settings - Fork 0
/
navmenu.js
67 lines (55 loc) · 2.15 KB
/
navmenu.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
window.onload = () => {
const navMenu = document.querySelector('nav-menu');
const navItem = document.querySelector('nav-item');
const hambuger = document.querySelector('nav-toggle');
const toggle = e => e.classList.toggle('is-active');
const toggleNav = ({ target }) => Array.from(navMenu.classList).includes('is-active') ? toggle(navMenu) : null;
hambuger.addEventListener('click', () => toggle(navMenu, 'is-active'));
Array.from(navItem).forEach(e => e.addEventListener('click', toggleNav));
}
const form = document.querySelector('form');
form.addEventListener('submit', function (event) {
event.preventDefault();
//This will validate the name field
const nameField = form.querySelector('input[name="name"]');
if (nameField.value === '') {
alert('Please enter your name.');
return;
}
//This will validate the email field
const emailField = form.querySelector('input[name="email"]');
if (emailField.value === '') {
alert('Please enter a valid email address.');
return;
} else if (!emailField.value.match(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,7}$/)) {
alert('Please enter a valid email address.');
return;
}
//This will validate the mobile field
const mobileField = form.querySelector('input[name="mobile"]');
if (mobileField.value === '') {
alert('Please enter a valid phone number.');
return;
} else if (!mobileField.value.match(/^\d{10}$/)) {
alert('Please enter a valid phone number.');
}
//This will validate the date field
const dateField = form.querySelector('input[name="date"]');
if (dateField.value === '') {
alert('Please select a date.');
return;
}
//This will validate the time field
const timeField = form.querySelector('input[name="time"]');
if (timeField.value === '') {
alert('Please enter a time.');
return;
}
//This will validate the service field
const serviceField = form.querySelector('select[name="service"]');
if (serviceField.value === '') {
alert('Please select a service.');
return;
}
form.submit();
});