-
Notifications
You must be signed in to change notification settings - Fork 0
/
address.js
77 lines (61 loc) · 2.07 KB
/
address.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
let cartData = JSON.parse(localStorage.getItem("cart")) || [];
let totMrp = document.getElementById("tot-price")
let totDis = document.getElementById("tot-dis")
let totPrice = document.getElementById("pay-amount")
let dilCharge = document.getElementById("free-del")
let savings = document.getElementById("savings")
let Tmrp = 0;
let TPrice = 0;
for (let i = 0; i < cartData.length; i++) {
Tmrp += cartData[i].mrp * cartData[i].quantity
TPrice += Number(cartData[i].Price) * cartData[i].quantity
}
console.log(Tmrp)
console.log(TPrice)
totMrp.innerText = `₹${Tmrp}`;
totPrice.innerText = `₹${TPrice}`;
if (+cartData.length > 0) {
if (TPrice > 500) {
dilCharge.innerText = "FREE"
}
}
savings.innerText = (Tmrp - TPrice)
totDis.innerText = `- ₹${(Tmrp - TPrice)}`
let order_summery_count = document.getElementById("order-summery-count")
order_summery_count.innerText = cartData.length;
let nameInp = document.getElementById("name-inp");
let mobileInp = document.getElementById("mobile-inp");
let addressInp = document.getElementById("address-inp");
let pinInp = document.getElementById("pin-inp");
let formInp = document.getElementById("form-input");
let landmarkInp = document.getElementById("landmark-inp")
let AddressData = JSON.parse(localStorage.getItem("Address-Data")) || [];
formInp.addEventListener("submit", (event) => {
event.preventDefault()
if (nameInp.value == "" || mobileInp.value == "" || addressInp == "" || pinInp.value == "" || AddressData == []) {
alert(`Please Fill All Madatory Fields`);
}
else {
location.href = `payment.html`
if (landmarkInp.value == "") {
let obj = {
name: nameInp.value,
mobile: mobileInp.value,
address: addressInp.value,
pin: pinInp.value
}
AddressData.push(obj)
}
else {
let obj = {
name: nameInp.value,
mobile: mobileInp.value,
address: addressInp.value,
landmark: landmarkInp.value,
pin: pinInp.value
}
AddressData.push(obj)
}
localStorage.setItem("Address-Data", JSON.stringify(AddressData));
}
})