const updateBtn = document.getElementById("update-button"); const serviceInput = document.getElementById("service-input") const coastInput = document.getElementById("coast-input") const dateInput = document.getElementById("date-input") const contractId = document.getElementById("contr-id").dataset.id contracts = [] window.addEventListener("load", () => { const contractsResponse = $.ajax({ url: `/contracts/getallbyuser`, type: "GET", contentType: "json" }); contracts = contractsResponse; }) const correctData = () => { return true; }; updateBtn.addEventListener("click", () => { if (!correctData()) { return; } let contract = { "Id": parseInt(contractId), "Service": serviceInput.value, "Coast": parseFloat(coastInput.value), "Date": new Date(dateInput.value), }; console.log(contract) $.ajax({ url: "/contracts/update", type: "POST", contentType: "application/json", data: JSON.stringify(contract) }).done(() => { window.location.href = "/Home/Contracts"; }); });