function calculate_total() { var total = 0 items = document.getElementsByClassName("order_item") for (const item of items){ price = parseInt(item.dataset.price) count = parseFloat(item.value) total += count * price } document.getElementById("total_price").innerText = total + "zł" } function min(a, b) { if (a > b) { return a } return b } function increase(id) { input = document.getElementById(id) step = parseFloat(input.step) input.value= min(parseFloat(input.value)+step, 0) calculate_total() } function decrease(id) { input = document.getElementById(id) step = parseFloat(input.step) input.value= min(parseFloat(input.value)-step, 0) calculate_total() } document.body.addEventListener('htmx:beforeSwap', e => { if (e.detail.xhr.status >= 400) { e.detail.shouldSwap = true; e.detail.isError = false; } }); calculate_total()