('#appointmentForm').submit(function(e) {
e.preventDefault();
var date = ('#date').val();
var time = ('#time').val();
var description = ('#description').val();
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');
});
(document).on('click', '.appointment', function() {
var time = (this).find('.time').text();
var description = (this).closest('td').data('date');
('#time').val(time);
('#appointmentModal').css('display', 'block');
$(this).remove();
});
Assistant
Update the HTML form by adding a button with class "delete" inside the appointmentModal div:
Description:
Save Changes
Update the script.js file by adding a click event listener to the delete button, which removes the appointment div from the calendar:
(document).ready(function() {
('#appointmentForm').submit(function(e) {
e.preventDefault();
var date = ('#date').val();
var time = ('#time').val();
var description = $('#description').val();
var appointmentHTML = ...
});
$('[data-date="' + date + '"]').append(appointmentHTML);
// Reset form inputs
$('#date').val('');
$('#time').val('');
$('#description').val('');
// Hide the modal
$('#appointmentModal').css('display', 'none');
// Handle form submission
$("#appointmentForm").submit(function(event) {
event.preventDefault();
// 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');