// Function to handle input change events for text inputs and textareas
function handleInputChange(event) {
// Get the label associated with the input
const label = event.target.previousElementSibling;
// Add or remove 'filled' class based on whether input has content
label.classList.toggle('filled', event.target.value.trim() !== '');
}
// Add input event listeners to all input and textarea elements
document.querySelectorAll('input, textarea').forEach((input) => {
input.addEventListener('input', handleInputChange);
});
// Initialize variables for tracking and limiting the number of items
let currentItemNumber = 2;
const maxItems = 5;
// Function to add a new item (label and textarea) to the form
function addItem() {
// Check if the maximum number of items has been reached
if (currentItemNumber holiday.getTime() === minDate.getTime())) {
minDate.setDate(minDate.getDate() + 1);
}
// Format the minimum date as a string and set it as the attribute
const formattedMinDate = minDate.toISOString().split('T')[0];
dateInput.setAttribute('min', formattedMinDate);
}
// Call the function to update date constraints
updateDateConstraints();
// Function to compose and send an email
function sendEmail() {
// Get values from form elements
const name = document.getElementById('name').value;
const email = document.getElementById('email').value;
const phoneNumber = document.getElementById('phone-number').value;
const pickupDate = document.getElementById('date').value;
const emailSubject = document.getElementById('email-subject').value;
// Compose the email body including item details
let items = '';
for (let i = 1; i < currentItemNumber; i++) {
const itemValue = document.getElementById(`item${i}`).value;
items += `Item ${i}: ${itemValue}%0D%0A`;
}
// Compose the subject and body of the email
const subject = "Order Information";
const body = `Name: ${name}%0D%0AEmail: ${email}%0D%0APhone Number: ${phoneNumber}%0D%0APickup Date: ${pickupDate}%0D%0A${items}`;
// Create a mailto link with the subject and body
const mailtoLink = `mailto:saga.holmstrom@eduvantaa.fi?subject=${subject}&body=${body}`;
// Open the default email client with the pre-filled email
window.location.href = mailtoLink;
}