I have some code on a page for a cart system with the following:
<div class="number-input">
<button onclick="this.parentNode.querySelector('input[type=number]').stepDown();preventDefault(); updateCartItems('2371') " ></button>
<input class="quantity" id="addQuantity-2371" min="1" name="cart_quantity[]" value="5" step="1" type="number">
<button onclick="$(this).prev()[0].stepUp();preventDefault(); updateCartItems('2371') " class="plus">
</button>
</div>
I am looking to call a function, in addition to changing the displayed value:
function updateCartItems(itemId) { // begin document ready
var products_id = parseInt(itemId);
var quantity = document.getElementById('addQuantity-' + itemId);
if (quantity) {
var cart_quantity = parseInt(quantity.value);
} else {
var cart_quantity = parseInt(1);
};
$.ajax({
url: 'ajax_add_saved_product.php',
method: "post",
dataType : "html",
data: {cart_quantity, products_id},
success: function (response, textStatus, jqXHR) {
alert(response);
$('#cartData').html(response);
update_cart_total();
update_free_products();
update_shipping_estimate();
},
error: function (jqXHR, textStatus, errorThrown) {
alert(xhr.responseText);
},
});
};
Issue is that I am not calling the updateCartItems function. Am I doing the call correctly?