aboutsummaryrefslogtreecommitdiff
path: root/public/cart.js
diff options
context:
space:
mode:
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
+ }),
+ });
+ });
+}