-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
102 lines (82 loc) · 3.74 KB
/
Copy pathscript.js
File metadata and controls
102 lines (82 loc) · 3.74 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
// script.js
// Array to hold booked appointments
const bookedAppointments = [];
// Function to save the profile information
function saveProfile() {
const formElements = {
name: document.getElementById("name").value,
age: document.getElementById("age").value,
weight: document.getElementById("weight").value,
height: document.getElementById("height").value,
temperature: document.getElementById("temperature").value,
symptoms: document.getElementById("symptoms").value
};
// Display the saved profile information
updateProfileDisplay(formElements);
// Show the profile display section
document.getElementById("profileDisplay").style.display = "block";
// Clear the form fields
document.getElementById("healthForm").reset();
}
// Function to update profile display
function updateProfileDisplay(profileData) {
for (const [key, value] of Object.entries(profileData)) {
document.getElementById(`display${capitalizeFirstLetter(key)}`).textContent = value;
}
}
// Capitalize the first letter of a string
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
// Function to update available time slots based on selected doctor and date
function updateTimeSlots() {
const doctor = document.getElementById("doctor").value;
const appointmentDate = document.getElementById("appointmentDate").value;
const timeSlots = document.getElementById("timeSlots");
timeSlots.innerHTML = ""; // Clear previous time slots
// Example time slots (this logic can be modified based on real data)
const availableSlots = ["09:00 AM", "10:00 AM", "11:00 AM", "02:00 PM", "03:00 PM"];
availableSlots.forEach(slot => {
const row = createTimeSlotRow(slot, doctor, appointmentDate);
timeSlots.appendChild(row);
});
}
// Function to create a time slot row
function createTimeSlotRow(slot, doctor, date) {
const row = document.createElement("tr");
const timeCell = document.createElement("td");
const availabilityCell = document.createElement("td");
timeCell.textContent = slot;
availabilityCell.innerHTML = `<button onclick="bookAppointment('${doctor}', '${date}', '${slot}')">Book</button>`;
row.appendChild(timeCell);
row.appendChild(availabilityCell);
return row;
}
// Function to book an appointment and update local storage
function bookAppointment(doctor, date, time) {
const appointment = { doctor, date, time };
// Store the appointment in local storage
const storedAppointments = JSON.parse(localStorage.getItem('bookedAppointments')) || [];
storedAppointments.push(appointment);
localStorage.setItem('bookedAppointments', JSON.stringify(storedAppointments));
// Alert the user and update the appointment list
alert(`Appointment booked with ${doctor} on ${date} at ${time}.`);
updateAppointmentList();
}
// Function to update the booked appointments list display
function updateAppointmentList() {
const appointmentList = document.getElementById("appointmentList");
const storedAppointments = JSON.parse(localStorage.getItem('bookedAppointments')) || [];
appointmentList.innerHTML = ""; // Clear previous appointments
if (storedAppointments.length === 0) {
appointmentList.innerHTML = "<p>No appointments booked yet.</p>";
} else {
storedAppointments.forEach(appointment => {
const listItem = document.createElement("p");
listItem.textContent = `${appointment.doctor} - ${appointment.date} at ${appointment.time}`;
appointmentList.appendChild(listItem);
});
}
}
// Call this function on page load to display previously booked appointments
window.onload = updateAppointmentList;