-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.html
79 lines (74 loc) · 2.79 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
77
78
79
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Women's Online Shopping - Cart</title>
<link rel="stylesheet" href="style.css">
<script src="scripts.js"></script>
</head>
<body>
<header>
<h1>Iram's Online Botique</h1>
<div class="cart-icon">
<span id="cartCount" class="cart-count">0</span>
<img src="images/cart.png" alt="Cart" class="cart-icon" width="30" height="30">
<div id="cartDropdown" class="dropdown-content">
<div id="cartItems">Your cart is empty</div>
</div>
</div>
</header>
<nav>
<a href="index.html">Home</a>
<a href="newarrival.html">New Arrivals</a>
<a href="clothing.html">Clothing</a>
<a href="accessories.html">Accessories</a>
<a href="sale.html">Sale</a>
<a href="contact.html">Contact</a>
<a href="cart.html">Cart</a>
</nav>
<div class="container">
<h2>Your Shopping Cart</h2>
<div id="cartItemsContainer">
<p>Your cart is empty</p>
</div>
</div>
<div>
<button type="submit" class="styled-button"><a href="checkout.html">Payment</a></button>
</div>
<footer>
© 2024 Iram's Online Botique. All rights reserved.
</footer>
<script>
document.addEventListener('DOMContentLoaded', function () {
updateCartItems();
function updateCartItems() {
let cart = JSON.parse(localStorage.getItem('cart')) || [];
let cartItemsContainer = document.getElementById('cartItemsContainer');
cartItemsContainer.innerHTML = '';
if (cart.length === 0) {
cartItemsContainer.innerHTML = '<p>Your cart is empty</p>';
} else {
cart.forEach((item, index) => {
let itemDiv = document.createElement('div');
itemDiv.className = 'cart-item';
itemDiv.innerHTML = `
<span>${item.name} - ${item.price}kr</span>
<button class="remove-from-cart" onclick="removeFromCart(${index})">Remove</button>
`;
cartItemsContainer.appendChild(itemDiv);
});
}
}
window.removeFromCart = function (index) {
let cart = JSON.parse(localStorage.getItem('cart')) || [];
cart.splice(index, 1);
localStorage.setItem('cart', JSON.stringify(cart));
updateCartCount();
updateCartItems();
};
updateCartCount();
});
</script>
</body>
</html>