-
Notifications
You must be signed in to change notification settings - Fork 1
/
showHideCart.html
137 lines (100 loc) · 2.91 KB
/
showHideCart.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
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
<html>
<meta charset="UTF-8" />
<style>
li {
cursor: cell;
}
.infoBox {
background-color: gray;
border: 1px dashed darkred;
margin-top: 50px ;
width: 100%;
display: none;
}
.badge {
position: absolute;
top: 20px;
right: 30px;
padding: 5px 10px;
border-radius: 50%;
background: red;
color: white;
}
.bild {
width: 80px;
height: 80px;
float: right;
}
.cart {
float : right;
}
#Cart td {
border: 1px dotted black;
background-color: lightseagreen;
padding: 5px;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
font-size: medium;
width: 20%;
}
</style>
<script>
var counter = 0;
var total = 0;
function rensa() {
var tabell = document.getElementById("Cart");
tabell.innerHTML = "<tr><td>Name</td><td>Pris</td></tr>";
counter = 0;
total = 0;
updateElements();
}
function toggleCart() {
var x = document.getElementById("purchaseInfo");
if (x.style.display != "block") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
function add2Cart(namn, pris) {
console.log(namn + " kostar " + pris + " SEK");
var tabell = document.getElementById("Cart");
var rad = tabell.insertRow();
var cell1 = rad.insertCell();
cell1.innerHTML = namn;
var cell2 = rad.insertCell();
cell2.innerHTML = pris + " SEK";
total += pris;
counter++;
updateElements();
}
function updateElements(){
document.getElementById("totalsum").innerHTML = "Total: " + total + " SEK";
document.getElementById("counter").innerHTML = counter;
}
</script>
<Body>
<div id="shoppingTable" class="cart">
<span class="badge" id="counter">0</span>
<img class="bild" src="shopping_cart.png" onclick="toggleCart();" /><br/><br/>
<div id="totalsum">0 SEK</div>
<div id="purchaseInfo" class="InfoBox">
<table id="Cart">
<tr>
<td>Name</td>
<td>Pris</td>
</tr>
</table>
<button onclick="rensa()">Rensa! </button>
</div>
</div>
<div class="lista">
<ul style=" width: 60%;">
<li onclick="add2Cart('Nike Air', 1299)">Nike air</li>
<li onclick="add2Cart('Crogs', 299)">Crogs</li>
<li onclick="add2Cart('Converse ', 799)">Converse</li>
<li onclick="add2Cart('Salomon Mid-GTX', 2449)">Salomon Mid-GTX</li>
<li onclick="add2Cart('Haglöf Super Hike', 899)">Haglöf Super Hike</li>
</ul>
</div>
</Body>
</html>