piekarnikgosipl/js/order.js
2026-11-08 19:05:53 +01:00

33 lines
730 B
JavaScript

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()
}
calculate_total()