document.addEventListener("DOMContentLoaded", () => { fetch("getIncidents.php").then(res => res.json().then(json => { if(json.message === "ok") { let body = ""; for (const incident of json.incidents) { body += ``; } document.querySelector("#incident").innerHTML = body; } })); }); document.querySelector("#addFineForm").addEventListener("submit", e => { e.preventDefault(); let formData = new FormData(); formData.append("amount", document.querySelector("#amount").value); formData.append("points", document.querySelector("#points").value); formData.append("incident", document.querySelector("#incident").value) fetch("addFine.php", { method: "POST", body: formData }).then(res => res.json().then(json => { if(json.message === "ok") { alert("Fine added successfully"); } else { alert("Error adding fine"); } })); });