aboutsummaryrefslogtreecommitdiff
path: root/public/cart.js
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-06-01 16:02:10 +0200
committerlonkaars <loek@pipeframe.xyz>2023-06-01 16:02:10 +0200
commit879c72e50c172f6e20416dcf06fccdbb59525c7a (patch)
treed6cb693daa85b724eb3d07d8fae807b609cfd5c5 /public/cart.js
parent8af23ff155904ba78de61a3cdab33a048a0f5664 (diff)
order from product catalogue and modify cart product count
Diffstat (limited to 'public/cart.js')
-rw-r--r--public/cart.js22
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
+ }),
+ });
+ });
+}