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 }), }); }); }