rmitems / script.js
iacelectricals's picture
Update script.js
d6db1fb verified
Raw
History Blame Contribute Delete
1.32 kB
window.onload = async function () {
const queryParams = new URLSearchParams(window.location.search);
const itemDescription = queryParams.get('itemDescription');
// alert("item: " + itemDescription)
if (!itemDescription) {
alert("No item description provided!");
return;
}
try {
// Fetch data from the Google Sheets API or your backend
const response = await fetch(`https://iacelectricals-backendrmitem.hf.space/items?description=${encodeURIComponent(itemDescription)}`);
if (!response.ok) {
throw new Error("Failed to fetch item details.");
}
const data = await response.json();
// alert("data " + data)
// Populate the fields with the data
document.getElementById('item-description').value = data.ItemDescription || "N/A";
document.getElementById('item-code').value = data.ItemCode || "N/A";
document.getElementById('current-balance').value = data.CurrentBalance || 0;
document.getElementById('unit').value = data.Unit || "N/A";
document.getElementById('google-form-link').href = data.GoogleFormLink || "#";
} catch (error) {
console.error("Error fetching item details:", error);
alert("Error fetching item details. Please try again.");
}
};