diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-06-01 16:02:10 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-06-01 16:02:10 +0200 |
commit | 879c72e50c172f6e20416dcf06fccdbb59525c7a (patch) | |
tree | d6cb693daa85b724eb3d07d8fae807b609cfd5c5 /public/cart.js | |
parent | 8af23ff155904ba78de61a3cdab33a048a0f5664 (diff) |
order from product catalogue and modify cart product count
Diffstat (limited to 'public/cart.js')
-rw-r--r-- | public/cart.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/public/cart.js b/public/cart.js new file mode 100644 index 0000000..b8c9887 --- /dev/null +++ b/public/cart.js @@ -0,0 +1,22 @@ +var products = document.getElementById("products").getElementsByClassName("product"); + +for (var product of products) { + var countInput = product.getElementsByClassName("count")[0]; + countInput.removeAttribute("disabled"); + + // update product count in cart asynchronously when cart value is modified + countInput.addEventListener("input", function() { + var productID = this.parentElement.getAttribute("product-id"); + var count = this.value; + + fetch("/cart.php", { + method: "POST", + headers: { "Content-Type": "application/x-www-form-urlencoded" }, + body: new URLSearchParams({ + "type": "update", + "product_id": productID, + "count": count + }), + }); + }); +} |