('#appointmentForm').submit(function(e) {
e.preventDefault();
var date = ('#date').val();
var time = ('#time').val();
var description = ('#description').val();
code
var appointmentHTML =
'<div class="appointment">' +
'<span class="time">' +
time +
'</span>' +
'<span class="description">' +
description +
'</span>' +
'<span class="delete">×</span>' +
'</div>';
$('[data-date="' + date + '"]').append(appointmentHTML);
var appointments = $('[data-date="' + date + '"] .appointment');
appointments.sort(function(a, b) {
var timeA = $(a).find('.time').text();
var timeB = $(b).find('.time').text();
return timeA.localeCompare(timeB);
});
$('[data-date="' + date + '"]').empty().append(appointments);
$('#appointmentForm')[0].reset();
$('#appointmentModal').css('display', 'none');
Assistant
To add a delete button to the appointments and make it work, add the following code to the script.js file:
This code uses jQuery's .closest() method to find the closest parent element with the .appointment class and removes it from the DOM using the .remove() method.
To display the delete button in the appointment modal, modify the HTML code for the appointmentForm as follows:
Save Changes
This adds a new element with the class "delete" after the submit button in the form.
Finally, add the following CSS code to the style.css file:
// Handle form submission
$("#appointmentForm").submit(function(event) {
event.preventDefault();
code
// Get the form values
var date = $("#date").val();
var time = $("#time").val();
var description = $("#description").val();
alert("Appointment Details:\n\nDate: " + date + "\nTime: " + time + "\nDescription: " + description);
modal.style.display = "none";
});
});
(document).ready(function() {
var appointmentForm = ('#appointmentForm');
var dateInput = ('#date');
var timeInput = ('#time');
var descriptionInput = $('#description');
// Get the appointment details
var date = dateInput.val();
var time = timeInput.val();
var description = descriptionInput.val();
var dayCell = $('td[data-date="' + date + '"]');
var appointmentElement = $('<div class="appointment">' +
'<div class="time">' + time + '</div>' +
'<div class="description">' + description + '</div>' +
'</div>');
dayCell.append(appointmentElement);
// Reset the form inputs
dateInput.val('');
timeInput.val('');
descriptionInput.val('');
});
});
(document).ready(function() {
var appointmentForm = ('#appointmentForm');
var dateInput = ('#date');
var timeInput = ('#time');
var descriptionInput = $('#description');
form input[type="text"],
form button[type="submit"] {
display: block;
margin-top: 5px;
}
form button[type="submit"] {
margin-top: 10px;
}
make a button that allows you to delete the appointment after you make it. Add the script.js code to make the delete button work