aboutsummaryrefslogtreecommitdiff
path: root/public/cart.js
blob: b8c988775213fd6bf1defe8e575329567b2aa2f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
			}),
		});
	});
}