const orders = document.getElementById("orders"); const sandwich = document.getElementById("sandwich"); const day = document.getElementById("day"); const locals = { sandwich: document.querySelector("#oderCreator label").innerHTML, day: document.querySelector("label[for=day]").innerText, give: document.getElementById("dummy").innerText }; function lastOrderId() { if (orders.lastChild) return parseInt(orders.lastChild.id.replace("order", "")); return 0; } document.getElementById("addOrder").addEventListener("click", () => { if (!sandwich.value || !day.value) return; let id = lastOrderId() + 1; orders.insertAdjacentHTML("beforeend", `

remove
`); M.updateTextFields(); sandwich.selectedIndex = 0; day.value = ""; let order = document.getElementById("order"+id); order.querySelector("a").addEventListener("click", () => { order.remove(); if (lastOrderId() === 0) { sandwich.required = true; day.required = true; } }); document.getElementById("order"+id).scrollIntoView({behavior: "smooth"}); }); document.querySelector("form").addEventListener("submit", () => { return lastOrderId(); });