Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let addtocart_buttons = document.querySelectorAll('.add-to-cart-btn');
- addtocart_buttons.forEach((addToCartBtn) => {
- addToCartBtn.addEventListener('click', (button) => {
- let id = button.target.getAttribute('data-id');
- let quantity = button.target.previousElementSibling.value;
- console.log(quantity);
- if (quantity < 0) {
- alert("Please enter a quantity");
- } else {
- let data = new FormData;
- data.append('id', id);
- data.append('quantity', quantity);
- fetch("../../controllers/process-update-cart.php",
- {
- method: "POST",
- body : data
- })
- .then((response) => {
- return response.text();
- })
- .then((data_from_fetch) => {
- console.log(data_from_fetch);
- });
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement