-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.js
68 lines (58 loc) · 1.92 KB
/
code.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
const queryMobileMenu = document.getElementById('MobileMenu');
//For Mobile Menu
// eslint-disable-next-line no-unused-vars
function MobileMenu () {
if ( queryMobileMenu.style.display == 'block') {
queryMobileMenu.style.display = 'none';
} else {
queryMobileMenu.style.display = 'block';
}
}
// For email Validation.
const contact_form = document.getElementById('contact-form');
const email = document.getElementById('email');
const emailLabel = document.getElementById('label-email');
const underCase = /^[a-z0-9_.+-]+@[a-z0-9-]+\.[a-z0-9-.]+$/;
// eslint-disable-next-line no-unused-vars
function email_validation() {
if (underCase.test(email.value)) {
contact_form.submit();
contact_form.reset();
emailLabel.style.display = 'none';
email.style.border = 'none';
return false;
} else {
emailLabel.style.display = 'block';
email.style.border = '3px solid red';
return false;
}
}
//For local Storage
const fullName = document.getElementById('fullName');
const contactText = document.getElementById('contactText');
document.addEventListener('focusout', saveStorage);
function saveStorage() {
//javaScript object
const contactForm = {
fullName: fullName.value,
email: email.value,
contactText: contactText.value
};
localStorage.setItem('contactForm', JSON.stringify(contactForm));
}
function readStorageValues() {
if (localStorage.getItem('contactForm')) {
const contactForm = JSON.parse(localStorage.getItem('contactForm'));
const currentName = contactForm.fullName;
const currentEmail = contactForm.email;
const currentTextarea = contactForm.contactText;
fullName.value = currentName;
email.value = currentEmail;
contactText.value = currentTextarea;
} else {
fullName.value = '';
email.value = '';
contactText.value = '';
}
}
window.addEventListener('load', readStorageValues);