Spaces:
Running
Running
File size: 6,060 Bytes
5cc830e c821e69 f282b32 c821e69 5cc830e c821e69 5cc830e c821e69 f282b32 5cc830e c821e69 5cc830e c821e69 f282b32 c821e69 |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Checkout</title>
<link rel="stylesheet" href="style.css">
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100">
<div class="container mx-auto p-8">
<h1 class="text-2xl font-bold mb-4">Checkout</h1>
<div id="cart-summary" class="mb-8">
<h2 class="text-xl font-semibold mb-2">Cart Summary</h2>
<table class="table-auto w-full">
<thead>
<tr>
<th class="px-4 py-2">Product</th>
<th class="px-4 py-2">Name</th>
<th class="px-4 py-2">Quantity</th>
<th class="px-4 py-2">Price</th>
</tr>
</thead>
<tbody id="cart-items">
</tbody>
</table>
<div class="mt-4 font-bold">
Total: <span id="cart-total"></span>
</div>
</div>
<div id="shipping-info" class="mb-8">
<h2 class="text-xl font-semibold mb-2">Shipping Information</h2>
<form id="shipping-form" class="max-w-lg">
<div class="mb-4">
<label for="name" class="block text-gray-700 text-sm font-bold mb-2">Name:</label>
<input type="text" id="name" name="name" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
<div class="mb-4">
<label for="address" class="block text-gray-700 text-sm font-bold mb-2">Address:</label>
<input type="text" id="address" name="address" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
<div class="mb-4">
<label for="city" class="block text-gray-700 text-sm font-bold mb-2">City:</label>
<input type="text" id="city" name="city" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
<div class="mb-4">
<label for="zip" class="block text-gray-700 text-sm font-bold mb-2">Zip Code:</label>
<input type="text" id="zip" name="zip" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
</form>
</div>
<div id="payment-info" class="mb-8">
<h2 class="text-xl font-semibold mb-2">Payment Information</h2>
<form id="payment-form" class="max-w-lg">
<div class="mb-4">
<label for="card-number" class="block text-gray-700 text-sm font-bold mb-2">Card Number:</label>
<input type="text" id="card-number" name="card-number" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
<div class="mb-4">
<label for="expiry" class="block text-gray-700 text-sm font-bold mb-2">Expiry Date:</label>
<input type="text" id="expiry" name="expiry" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
<div class="mb-4">
<label for="cvv" class="block text-gray-700 text-sm font-bold mb-2">CVV:</label>
<input type="text" id="cvv" name="cvv" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
</form>
</div>
<button id="place-order" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline">Place Order</button>
<div id="confirmation-message" class="mt-8 text-green-500 font-bold hidden">
Your order has been placed!
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
const cartItems = JSON.parse(localStorage.getItem('cart')) || [];
const cartItemsContainer = document.getElementById('cart-items');
const cartTotalElement = document.getElementById('cart-total');
const placeOrderButton = document.getElementById('place-order');
const confirmationMessage = document.getElementById('confirmation-message');
let cartTotal = 0;
cartItems.forEach(item => {
const row = document.createElement('tr');
row.innerHTML = `
<td class="px-4 py-2"><img src="${item.image}" alt="${item.name}" class="w-16 h-16"></td>
<td class="px-4 py-2">${item.name}</td>
<td class="px-4 py-2">${item.quantity}</td>
<td class="px-4 py-2">$${item.price * item.quantity}</td>
`;
cartItemsContainer.appendChild(row);
cartTotal += item.price * item.quantity;
});
cartTotalElement.textContent = '$' + cartTotal;
placeOrderButton.addEventListener('click', function () {
confirmationMessage.classList.remove('hidden');
localStorage.removeItem('cart');
cartItemsContainer.innerHTML = '';
cartTotalElement.textContent = '$0';
});
});
</script>
</body>
</html> |