diff --git a/index.html b/index.html index b1ebcad..8ebb802 100644 --- a/index.html +++ b/index.html @@ -9,7 +9,17 @@ +
+ + +
+ + + + + + - - + + diff --git a/scripts/main.js b/scripts/main.js index 1cee2fe..03509c8 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -1,5 +1,7 @@ var all_products +let barcodeForm + async function makeAPIRequest(request) { try { const response = await fetch(request); @@ -14,13 +16,30 @@ async function loadProducts() { const loadProductRequest = new Request("http://127.0.0.1:8000/products") all_products = await makeAPIRequest(loadProductRequest) console.log("Loaded products:", all_products) - } - -function scan_product() { - const barcode = document.getElementById('barcode_input').value - for (index = 0; index < all_products.length; index++) { - if (all_products[index].barcode == barcode) { - console.log(all_products[index]) + barcodeForm = document.getElementById("barcode_form"); + barcodeForm.addEventListener("submit", (e) => { + e.preventDefault(); + + console.log('help') + + const barcode = document.getElementById('barcode_input').value + var chosen_product + for (index = 0; index < all_products.length; index++) { + if (all_products[index].barcode == barcode) { + chosen_product = all_products[index] + } } - } -} \ No newline at end of file + + barcode_input.value = "" + + const product_image_placeholders = document.getElementsByClassName('product_image') + console.log(product_image_placeholders) + for (index = 0; index < product_image_placeholders.length; index++) { + console.log(product_image_placeholders[index].src) + if (product_image_placeholders[index].src == "") { + product_image_placeholders[index].src = chosen_product.image_url + return false + } + } + }); + }