DIDS-Coursework/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/js/addFine.js
rodude123 a6d2a0c17b Created the ability to add fines
Signed-off-by: rodude123 <rodude123@gmail.com>
2022-12-15 23:25:00 +00:00

41 lines
1.1 KiB
JavaScript

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");
}
}));
});