order validation

This commit is contained in:
bronku 2026-11-08 19:05:53 +01:00
parent 2a4110ee8c
commit de22166113
6 changed files with 164 additions and 7 deletions

View file

@ -1,16 +1,33 @@
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()