-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
128 lines (109 loc) · 4.02 KB
/
script.js
File metadata and controls
128 lines (109 loc) · 4.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* =========================================
1. MOBILE MENU TOGGLE
========================================= */
const menuToggle = document.querySelector('.menu-toggle');
const navLinks = document.querySelector('.nav-links');
if (menuToggle && navLinks) {
menuToggle.addEventListener('click', () => {
navLinks.style.display = (navLinks.style.display === 'flex') ? 'none' : 'flex';
navLinks.style.flexDirection = 'column';
navLinks.style.position = 'absolute';
navLinks.style.top = '60px';
navLinks.style.right = '0';
navLinks.style.background = '#0056b3';
navLinks.style.width = '100%';
navLinks.style.padding = '20px';
});
}
/* =========================================
2. HOME CAROUSEL LOGIC
========================================= */
const carouselSlide = document.querySelector('.carousel-slide');
const carouselImages = document.querySelectorAll('.carousel-item');
const prevBtn = document.querySelector('#prevBtn');
const nextBtn = document.querySelector('#nextBtn');
if (carouselSlide) {
let counter = 0;
const size = 100;
function updateSlide() {
carouselSlide.style.transform = 'translateX(' + (-size * counter) + '%)';
}
nextBtn.addEventListener('click', () => {
if (counter >= carouselImages.length - 1) counter = -1;
counter++;
updateSlide();
});
prevBtn.addEventListener('click', () => {
if (counter <= 0) counter = carouselImages.length;
counter--;
updateSlide();
});
setInterval(() => {
if (counter >= carouselImages.length - 1) counter = -1;
counter++;
updateSlide();
}, 5000);
}
/* =========================================
3. BOOKING LOGIC
========================================= */
function bookNow(doctorName) {
localStorage.setItem('selectedDoctor', doctorName);
window.location.href = 'booking.html';
}
const bookingForm = document.getElementById('bookingForm');
if (bookingForm) {
const savedDoctor = localStorage.getItem('selectedDoctor');
const doctorSelect = document.getElementById('doctorSelect');
if (savedDoctor && doctorSelect) {
doctorSelect.value = savedDoctor;
}
bookingForm.addEventListener('submit', function(e) {
e.preventDefault();
const pName = document.getElementById('pName').value;
const pDoctor = document.getElementById('doctorSelect').value;
const pDate = document.getElementById('pDate').value;
const pTime = document.getElementById('pTime').value;
const selectedDate = new Date(pDate);
const today = new Date();
today.setHours(0, 0, 0, 0);
if (selectedDate < today) {
alert('Error: You cannot select a past date.');
return;
}
const appointment = {
name: pName,
doctor: pDoctor,
date: pDate,
time: pTime
};
localStorage.setItem('appointmentDetails', JSON.stringify(appointment));
window.location.href = 'confirmation.html';
});
}
/* =========================================
4. CONFIRMATION DISPLAY
========================================= */
const confDetails = document.getElementById('confDetails');
if (confDetails) {
const dataString = localStorage.getItem('appointmentDetails');
if (dataString) {
const data = JSON.parse(dataString);
document.getElementById('confName').innerText = data.name;
document.getElementById('confDoc').innerText = data.doctor;
document.getElementById('confDateTime').innerText = `${data.date} at ${data.time}`;
} else {
window.location.href = 'index.html';
}
}
/* =========================================
5. CONTACT FORM
========================================= */
const contactForm = document.getElementById('contactForm');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
alert('Message Sent Successfully!');
contactForm.reset();
});
}