-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
53 lines (46 loc) · 2.02 KB
/
script.js
File metadata and controls
53 lines (46 loc) · 2.02 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
document.addEventListener("DOMContentLoaded", function () {
document.querySelector(".visit-btn").addEventListener("click", function () {
alert("Book Haven | 123 Bookstore Rd | Bookstore, SC 12345");
});
const searchForms = document.querySelectorAll(".search-section form");
searchForms.forEach((form) => {
const searchInputs = form.querySelectorAll("input[type='search']");
const submitButtons = form.querySelectorAll("input[type='submit']");
submitButtons.forEach((submitButton, index) => {
submitButton.addEventListener("click", function (event) {
event.preventDefault();
const searchInput = searchInputs[index];
const searchValue = searchInput.value.trim();
if (searchValue === "") {
alert("Please enter a search term.");
return;
} else {
alert(`Searching for ${submitButton.value}: ${searchValue}`);
}
});
});
});
const newsletterForm = document.querySelector(".newsletter form");
if (newsletterForm) {
newsletterForm.addEventListener("submit", function (event) {
const emailInput = document.getElementById("email").value.trim();
if (!validateEmail(emailInput)) {
event.preventDefault();
alert("Please enter a valid email address.");
} else {
alert("Thank you for signing up for our Newletter!");
}
});
}
function validateEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
const currentPage = window.location.pathname.split("/").pop();
document.querySelectorAll(".nav-links a").forEach((link) => {
if (link.getAttribute("href") === currentPage) {
link.style.fontWeight = "bold";
link.style.textDecoration = "underline";
}
});
});