-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbag.html
More file actions
153 lines (113 loc) · 3.3 KB
/
Copy pathbag.html
File metadata and controls
153 lines (113 loc) · 3.3 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>bag</title>
<style>
body{
padding: 5%;
}
#supMaindiv{
display: flex;
}
#md{
display: flex;
}
button{
color: white;
background-color: black;
border-radius: 25px;
width: 80%;
height: 60px;
text-align: center;
}
#summary{
margin-left: 30%;
}
</style>
</head>
<body>
<div id="md">
<div>
<div id = "product">
</div>
</div>
<div id="summary">
<h2>summary</h2>
<h3 id=subtotal>subtotal ₹</h3>
<p id="esti">Estimated delivery and handling ₹</p>
<hr>
<p id="totall">total ₹</p>
<hr>
<button onclick="checkout()">checkout</button>
</div>
</div>
<script>
//get data from localstorage
var price = 0;
var dcharge =200;
var total=0;
let parent = document.getElementById("product")
let bag=JSON.parse(localStorage.getItem("bag"));
function showProduct(){
bag.forEach(element => {
let maindiv= document.createElement("div")
maindiv.style.display="flex"
//for image---------------------------------------------
//creating image tag
let div1=document.createElement("div")
let img= document.createElement("img")
img.height=200
img.width=200
//asigning src value
img.src=element.image
//console.log(img)
//element.image
div1.append(img)
maindiv.append(div1)
//for image---------------------------------------------
//for data---------------------------------------------
let div2=document.createElement("div")
let div21=document.createElement("div")
let head1=document.createElement("h2")
let div22=document.createElement("div")
let p1=document.createElement("p")
let div23=document.createElement("div")
div21.textContent=element.a
head1.textContent=element.b
div22.textContent=element.c
p1.textContent=element.d//price of item
//console.log(element.d)
//console.log(Number(element.d))
price=price+(Number(element.d))
//console.log(cost)
div23.textContent=element.e
div2.append(div21,head1,div22,p1,div23)
maindiv.append(div2)
parent.append(maindiv)
});
//console.log(price)
if(price>7000){
dcharge=0;
}
total = price+dcharge
subtotal.append(price)
esti.append(dcharge)
totall.append(total)
}
showProduct()
if(localStorage.getItem("pdata")===null){
localStorage.setItem("pdata", JSON.stringify([]))
}
function checkout(){
let fdata = JSON.parse(localStorage.getItem("pdata"))
fdata.push({price,dcharge,total});
localStorage.setItem("pdata", JSON.stringify(fdata));
console.log("fdata:",fdata)
location.href="checkout.html"
}
</script>
</body>
</html>