2025-06-30 12:37:33 +02:00
|
|
|
let partySize = 0;
|
|
|
|
|
|
|
|
|
|
function createNewMember(id) {
|
|
|
|
|
const memberDiv = document.createElement("div");
|
|
|
|
|
memberDiv.classList.add("member");
|
|
|
|
|
|
2025-07-13 16:12:07 +02:00
|
|
|
const nameDiv = document.createElement("div");
|
2025-06-30 12:37:33 +02:00
|
|
|
|
|
|
|
|
const nameLabel = document.createElement("label");
|
|
|
|
|
nameLabel.htmlFor = `name-${id}`;
|
|
|
|
|
nameLabel.innerHTML = "Name:";
|
|
|
|
|
|
|
|
|
|
const nameInput = document.createElement("input");
|
|
|
|
|
nameInput.type = "text";
|
|
|
|
|
nameInput.id = `name-${id}`;
|
|
|
|
|
nameInput.name = `name-${id}`;
|
|
|
|
|
nameInput.required = true;
|
2025-07-13 16:12:07 +02:00
|
|
|
nameInput.style = "width:0;flex:1;";
|
2025-06-30 12:37:33 +02:00
|
|
|
|
2025-07-13 16:12:07 +02:00
|
|
|
nameDiv.appendChild(nameLabel);
|
|
|
|
|
nameDiv.appendChild(nameInput);
|
2025-06-30 12:37:33 +02:00
|
|
|
|
2025-07-13 16:12:07 +02:00
|
|
|
const childDiv = document.createElement("div");
|
2025-06-30 12:37:33 +02:00
|
|
|
|
|
|
|
|
const childLabel = document.createElement("label");
|
|
|
|
|
childLabel.htmlFor = `child-${id}`;
|
|
|
|
|
childLabel.innerHTML = "Child:";
|
|
|
|
|
|
|
|
|
|
const childInput = document.createElement("input");
|
|
|
|
|
childInput.type = "checkbox";
|
|
|
|
|
childInput.id = `child-${id}`;
|
|
|
|
|
childInput.name = `child-${id}`;
|
2025-07-13 16:12:07 +02:00
|
|
|
childInput.style = 'font-size: 1rem';
|
|
|
|
|
|
|
|
|
|
const childInputDiv = document.createElement("div");
|
|
|
|
|
childInputDiv.classList.add("fill-right");
|
2025-06-30 12:37:33 +02:00
|
|
|
|
2025-07-13 16:12:07 +02:00
|
|
|
childInputDiv.appendChild(childInput);
|
2025-06-30 12:37:33 +02:00
|
|
|
|
2025-07-13 16:12:07 +02:00
|
|
|
childDiv.appendChild(childLabel);
|
|
|
|
|
childDiv.appendChild(childInputDiv);
|
2025-06-30 12:37:33 +02:00
|
|
|
|
2025-07-13 16:12:07 +02:00
|
|
|
const dietDiv = document.createElement("p");
|
2025-06-30 12:37:33 +02:00
|
|
|
|
|
|
|
|
const dietLabel = document.createElement("label");
|
|
|
|
|
dietLabel.htmlFor = `diet-${id}`;
|
|
|
|
|
dietLabel.innerHTML = "Dietary preferences:";
|
|
|
|
|
|
|
|
|
|
const dietInput = document.createElement("textarea");
|
|
|
|
|
dietInput.id = `diet-${id}`;
|
|
|
|
|
dietInput.name = `dietaryPreferences-${id}`;
|
|
|
|
|
|
2025-07-13 16:12:07 +02:00
|
|
|
dietDiv.appendChild(dietLabel);
|
|
|
|
|
dietDiv.appendChild(dietInput);
|
|
|
|
|
|
|
|
|
|
const separatorDiv = document.createElement("div");
|
|
|
|
|
separatorDiv.classList.add("separator");
|
2025-06-30 12:37:33 +02:00
|
|
|
|
2025-07-13 16:12:07 +02:00
|
|
|
memberDiv.appendChild(separatorDiv);
|
|
|
|
|
memberDiv.appendChild(nameDiv);
|
|
|
|
|
memberDiv.appendChild(childDiv)
|
|
|
|
|
memberDiv.appendChild(dietDiv);
|
2025-06-30 12:37:33 +02:00
|
|
|
|
|
|
|
|
document.querySelector("div.members").appendChild(memberDiv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updatePartySize(newPartySize) {
|
|
|
|
|
if (newPartySize > partySize) {
|
|
|
|
|
for (let i = partySize; i < newPartySize; i++) {
|
|
|
|
|
createNewMember(partySize);
|
|
|
|
|
}
|
|
|
|
|
} else if (newPartySize < partySize) {
|
|
|
|
|
for (let i = partySize; i > newPartySize; i--) {
|
|
|
|
|
document.querySelector("div.members").lastChild.remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
partySize = newPartySize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.onload = function () {
|
|
|
|
|
const partySizeDropdown = document.querySelector("select#party-size");
|
|
|
|
|
partySizeDropdown.addEventListener("change", () => {
|
|
|
|
|
updatePartySize(Number.parseInt(partySizeDropdown.value));
|
|
|
|
|
});
|
|
|
|
|
updatePartySize(1);
|
|
|
|
|
};
|