-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
49 lines (43 loc) · 1.71 KB
/
script.js
File metadata and controls
49 lines (43 loc) · 1.71 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
document.addEventListener("DOMContentLoaded", function () {
// Form Validation
const contactForm = document.getElementById("contactForm");
if (contactForm) {
contactForm.addEventListener("submit", function (event) {
event.preventDefault(); // Prevent default form submission
let name = document.getElementById("name").value.trim();
let phone = document.getElementById("phone").value.trim();
let address = document.getElementById("address").value.trim();
if (name === "" || phone === "" || address === "") {
alert("Please fill in all the fields.");
return;
}
alert("Thank you! Your details have been submitted.");
contactForm.reset();
});
}
// Mobile Navigation Toggle
const navToggle = document.createElement("button");
navToggle.textContent = "☰ Menu";
navToggle.id = "navToggle";
document.querySelector("header").prepend(navToggle);
const nav = document.querySelector("nav ul");
navToggle.addEventListener("click", function () {
nav.classList.toggle("show");
});
// Smooth Scrolling for Navigation Links
const navLinks = document.querySelectorAll("nav ul li a");
navLinks.forEach(link => {
link.addEventListener("click", function (event) {
if (this.hash !== "") {
event.preventDefault();
let target = document.querySelector(this.hash);
if (target) {
window.scrollTo({
top: target.offsetTop - 60,
behavior: "smooth"
});
}
}
});
});
});