DIDS-Coursework/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/addFine.js

41 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

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 += `<option value="${incident.Incident_ID}">${incident.Incident_Report}${incident.Incident_Date}</option>`;
}
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");
}
}));
});