Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Product Table</title>
- <!-- Include Bootstrap CSS -->
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
- </head>
- <body>
- <div class="container mt-5">
- <div class="row">
- <div class="col-md-3">
- <div class="form-group">
- <label for="warehouseSelector">Select Warehouse:</label>
- <select class="form-control" id="warehouseSelector">
- <option value="warehouse1">Warehouse 1</option>
- <option value="warehouse2">Warehouse 2</option>
- <!-- Add more warehouse options as needed -->
- </select>
- </div>
- </div>
- <div class="col-md-9">
- <table class="table">
- <thead>
- <tr>
- <th>Product Image</th>
- <th>Product Name</th>
- <th>Inventory Left</th>
- <th>Action</th>
- </tr>
- </thead>
- <tbody id="productTableBody">
- <!-- Product rows will be dynamically added here based on the selected warehouse -->
- </tbody>
- </table>
- </div>
- </div>
- </div>
- <!-- Include Bootstrap JS and Popper.js -->
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.11.6/umd/popper.min.js"></script>
- <script>
- // Sample product data for different warehouses
- const productsByWarehouse = {
- warehouse1: [
- { name: 'Product 1', image: 'https://fastly.picsum.photos/id/0/5000/3333.jpg?hmac=_j6ghY5fCfSD6tvtcV74zXivkJSPIfR9B8w34XeQmvU', inventory: 10 },
- { name: 'Product 2', image: 'https://fastly.picsum.photos/id/0/5000/3333.jpg?hmac=_j6ghY5fCfSD6tvtcV74zXivkJSPIfR9B8w34XeQmvU', inventory: 5 },
- ],
- warehouse2: [
- { name: 'Product 3', image: 'https://fastly.picsum.photos/id/0/5000/3333.jpg?hmac=_j6ghY5fCfSD6tvtcV74zXivkJSPIfR9B8w34XeQmvU', inventory: 8 },
- { name: 'Product 4', image: 'https://fastly.picsum.photos/id/0/5000/3333.jpg?hmac=_j6ghY5fCfSD6tvtcV74zXivkJSPIfR9B8w34XeQmvU', inventory: 12 },
- ],
- };
- // Function to populate the product table based on the selected warehouse
- function populateProductTable(warehouse) {
- const productTableBody = document.getElementById('productTableBody');
- productTableBody.innerHTML = ''; // Clear existing rows
- const products = productsByWarehouse[warehouse];
- if (products) {
- products.forEach(product => {
- const row = document.createElement('tr');
- row.innerHTML = `
- <td><img src="${product.image}" alt="Product Image" width="100"></td>
- <td>${product.name}</td>
- <td>${product.inventory}</td>
- <td><button class="btn btn-primary">View Details</button></td>
- `;
- productTableBody.appendChild(row);
- });
- }
- }
- // Event listener for the warehouse selector
- const warehouseSelector = document.getElementById('warehouseSelector');
- warehouseSelector.addEventListener('change', function () {
- const selectedWarehouse = this.value;
- populateProductTable(selectedWarehouse);
- });
- // Initial population of the product table with the default selected warehouse
- populateProductTable(warehouseSelector.value);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement