-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.html
76 lines (69 loc) · 2.91 KB
/
cart.html
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
<!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">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>cart</title>
<link rel="stylesheet" href="bestseller.css">
</head>
<body>
<h5></h5>
<button class="carthead" onclick="paymentFunc()">Order Now</button>
<div id="container">
</div>
</body>
</html>
<script>
var cartData = JSON.parse(localStorage.getItem("cartData")) || [];
window.addEventListener("load",function (){
displayData(cartData);
})
function displayData(cartData) {
var length=cartData.length;
var total=0;
document.querySelector("#container").innerText = "";
cartData.map(function (e,i) {
total+=e.price;
var div = document.createElement("div");
var img = document.createElement("img");
img.src = e.img_url;
var p1 = document.createElement("p");
p1.innerText = e.name;
var p2 = document.createElement("p");
p2.setAttribute("id", "bestpricepara")
p2.innerText = "₹" + e.price;
var span = document.createElement("span");
var mark = document.createElement("del");
mark.innerText = "₹" + e.act_price;
span.append(mark);
p2.append(span);
var p3 = document.createElement("p3");
p3.innerText = "You Save ₹" + [e.act_price - e.price] + " [" + Math.round(100 - (e.price / e.act_price) * 100) + "% off]";
var p4 = document.createElement("p");
p4.innerText = e.nature;
var p5 = document.createElement("p");
p5.innerText = e.specification;
var btn=document.createElement("button");
btn.innerText="Remove From Cart";
btn.addEventListener("click",function (){
removeFun(e,i);
});
div.append(img, p1, p2, p3, p4, p5,btn);
document.querySelector("#container").append(div);
});
document.querySelector("h5").innerText="Total cart Item is:- "+length;
document.querySelector("h5").innerText="Total cart Item is:- "+length+"\n"+" Total Amount is :- "+total;
};
function removeFun(elem,index){
cartData.splice(index,1);
localStorage.setItem("cartData",JSON.stringify(cartData));
window.location.reload();
}
function paymentFunc(){
window.location.href="payment.html";
}
</script>