-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcartScript.js
35 lines (33 loc) · 1.28 KB
/
cartScript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function updateItemPrice(id) {
// console.log(id)
var i = id.charAt(4)
var itemtotal = parseFloat(document.getElementById("item" + i + "price").innerHTML) * parseInt(document
.getElementById("item" + i + "qty").value);
document.getElementById("item" + i + "total").innerHTML = itemtotal;
updateTotal();
}
function updateTotal() {
var total = 0;
var grandTotal = 0;
var deliveryCost = 0;
var discount = 0;
var i = 1;
while (document.getElementById("item" + i + "total") != null) {
total += parseFloat(document.getElementById("item" + i + "total").innerHTML)
i++;
}
document.getElementById("total").innerHTML = "₹ " + total;
if (total < 500) {
deliveryCost = total * 0.05
document.getElementById("delivery-fee").innerHTML = "₹ " + deliveryCost;
document.getElementById("discount").innerHTML = "₹ " + 0;
grandTotal = total + deliveryCost;
}
if (total > 500) {
discount = total * 0.05
document.getElementById("discount").innerHTML = "₹ " + discount;
document.getElementById("delivery-fee").innerHTML = "₹ " + 0;
grandTotal = total - discount;
}
document.getElementById("grandTotal").innerHTML = "₹ " + grandTotal;
}