order validation
This commit is contained in:
parent
2a4110ee8c
commit
de22166113
6 changed files with 164 additions and 7 deletions
17
js/order.js
17
js/order.js
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue