-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
71 lines (65 loc) · 2.42 KB
/
script.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
// Sticky Navbar
let header = document.querySelector('header');
let menu = document.querySelector('#menu-icon');
let navbar = document.querySelector('.navbar');
window.addEventListener('scroll', () => {
header.classList.toggle('shadow', window.scrollY > 0);
});
menu.onclick = () => {
navbar.classList.toggle('active');
}
window.onscroll = () => {
navbar.classList.remove('active');
}
// Dark Mode
let darkmode = document.querySelector('#darkmode');
darkmode.onclick = () => {
if(darkmode.classList.contains('bx-moon')){
darkmode.classList.replace('bx-moon','bx-sun');
document.body.classList.add('active');
}else{
darkmode.classList.replace('bx-sun','bx-moon');
document.body.classList.remove('active');
}
}
var submitButton = document.getElementById('submitButton');
submitButton.onclick = () =>{
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var message = document.getElementById('message').value;
if (name.trim() === '' && email.trim() === '' && message.trim() === '') {
alert('Please fill in all fields');
return false;
}
if (name.trim() === '') {
alert('Please enter the name');
return false;
}
if (name.trim().length < 3) {
alert('Name should be at least 3 characters');
return false;
}
if (email.trim() === '') {
alert('Please enter the email Id');
return false;
}
var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(email)) {
alert('Please enter a valid email address');
return false;
}
if (message.trim() === '') {
alert('Please enter the message');
return false;
}
// Basic email pattern matching
if (message.trim().length < 15) {
alert('message should be atleast 15 characters');
return false;
}
// Form is valid, you can submit it or perform additional actions
alert('🟢 Message sent successfully! ');
document.getElementById('name').value = '';
document.getElementById('email').value = '';
document.getElementById('message').value = '';
}