-
Notifications
You must be signed in to change notification settings - Fork 0
/
appoin.html
256 lines (212 loc) · 8.13 KB
/
appoin.html
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!--<?php include("connection.php"); ?>
<?php
if($_POST['submit'])
{
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$date = $_POST['date'];
$department = $_POST['department'];
$doctor = $_POST['doctor'];
$query = "insert into appointment values('$name','$phone','$email','$date','$department','$doctor');";
$data = mysqli_query($conn,$query);
if($data)
{
echo "YOUR APPOINTMENT IS BOOKED SUCCESSFULLY!!";
}
else
{
echo "YOUR APPOINTMENT FAILED";
}
}
?>-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Appointment Booking Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}
.container {
max-width: 500px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
margin-bottom: 20px;
}
input[type="text"],
input[type="email"],
input[type="date"],
input[type="submit"],
select {
width: calc(100% - 22px);
padding: 10px;
margin-top: 8px;
margin-bottom: 20px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
}
input[type="submit"] {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.error {
color: red;
font-size: 0.9em;
margin-top: -10px;
margin-bottom: 10px;
}
.success {
color: green;
font-size: 0.9em;
margin-top: -10px;
margin-bottom: 10px;
}
.copyright {
color: black;
margin-left: 25px;
}
</style>
</head>
<body style="background-color:rgb(163, 231, 240); ">
<div class="container">
<h1>Book Appointment</h1>
<form id="appointmentForm" action="success.html" >
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Your Name">
<div id="nameError" class="error"></div>
<label for="phno">Phone Number:</label>
<input type="text" id="phone" name="phone" placeholder="Your Phone Number">
<div id="phnoError" class="error"></div>
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Your Email">
<div id="emailError" class="error"></div>
<label for="date">Date:</label>
<input type="date" id="date" name="date">
<div id="dateError" class="error"></div>
<label for="department">Department:</label>
<select id="department" name="department" onchange="populateDoctors(this.value)" required>
<option value="">Select Department</option>
<option value="Cardiology">Cardiology</option>
<option value="Orthopedics">Orthopedics</option>
<option value="Neurology">Neurology</option>
</select>
<div id="departmentError" class="error"></div>
<label for="doctor">Doctor:</label>
<select id="doctor" name="doctor" required>
<option value="">Select Doctor</option>
<option value="Dr. John Smith">Dr. John Smith</option>
<option value="Dr. Sarah Johnson">Dr. Sarah Johnson</option>
<option value="Dr. Michael Williams">Dr. Michael Williams</option>
<option value="Dr. Emily Brown">Dr. Emily Brown</option>
<option value="Dr. David Jones">Dr. David Jones</option>
<option value="Dr. Jennifer Lee">Dr. Jennifer Lee</option>
</select>
<div id="doctorError" class="error"></div>
<input type="submit" value="Book Now" name="submit" class="submit">
<div id="successMessage" class="success" style="display: none;">Appointment successfully booked!</div>
</form>
</div>
<footer>
<span class="copyright">© 2024 MedCare</span>
</footer>
<script>
function populateDoctors(selectedDepartment) {
var doctorSelect = document.getElementById("doctor");
doctorSelect.innerHTML = "";
if (selectedDepartment === "Cardiology") {
addOption(doctorSelect, "Dr. John Smith");
addOption(doctorSelect, "Dr. Sarah Johnson");
} else if (selectedDepartment === "Orthopedics") {
addOption(doctorSelect, "Dr. Michael Williams");
addOption(doctorSelect, "Dr. Emily Brown");
} else if (selectedDepartment === "Neurology") {
addOption(doctorSelect, "Dr. David Jones");
addOption(doctorSelect, "Dr. Jennifer Lee");
}
}
function addOption(selectElement, optionText) {
var option = document.createElement("option");
option.text = optionText;
selectElement.add(option);
}
// Form validation function
function validateForm() {
var department = document.getElementById("department").value;
var doctorSelect = document.getElementById("doctor");
var doctor = doctorSelect.value;
// Department selection validation
if (department === "") {
document.getElementById('departmentError').innerHTML = "Please select a department";
return false;
} else {
document.getElementById('departmentError').innerHTML = "";
}
// Doctor selection validation
if (doctor === "") {
document.getElementById('doctorError').innerHTML = "Please select a doctor";
return false;
} else {
document.getElementById('doctorError').innerHTML = "";
}
var name = document.getElementById('name').value;
var phno = document.getElementById('phone').value;
var email = document.getElementById('email').value;
var date = document.getElementById('date').value;
document.getElementById('nameError').innerHTML = "";
document.getElementById('phnoError').innerHTML = "";
document.getElementById('emailError').innerHTML = "";
document.getElementById('dateError').innerHTML = "";
// Name validation
if (name.trim() === "") {
document.getElementById('nameError').innerHTML = "Please enter your name";
return false;
}
// Phone number validation
if (!/^\d{10}$/.test(phno)) {
document.getElementById('phnoError').innerHTML = "Please enter a valid 10-digit phone number";
return false;
}
// Email validation
if (!/\S+@\S+\.\S+/.test(email)) {
document.getElementById('emailError').innerHTML = "Please enter a valid email address";
return false;
}
// Date validation
if (date.trim() === "") {
document.getElementById('dateError').innerHTML = "Please select a date";
return false;
}
var selectedDate = new Date(date);
var currentDate = new Date();
currentDate.setHours(0, 0, 0, 0);
if (selectedDate < currentDate) {
document.getElementById('dateError').innerHTML = "Please select today or a future date";
return false;
}
// Display success message
document.getElementById('successMessage').style.display = "block";
// Redirect to success page after 3 seconds
setTimeout(function() {
window.location.href = "success.html";
}, 2000);
return false;
}
</script>
</body>
</html>