Advertisement
sourav8256

Untitled

Sep 16th, 2023
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Product Table</title>
  7. <!-- Include Bootstrap CSS -->
  8. <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
  9. </head>
  10. <body>
  11. <div class="container mt-5">
  12. <div class="row">
  13. <div class="col-md-3">
  14. <div class="form-group">
  15. <label for="warehouseSelector">Select Warehouse:</label>
  16. <select class="form-control" id="warehouseSelector">
  17. <option value="warehouse1">Warehouse 1</option>
  18. <option value="warehouse2">Warehouse 2</option>
  19. <!-- Add more warehouse options as needed -->
  20. </select>
  21. </div>
  22. </div>
  23. <div class="col-md-9">
  24. <table class="table">
  25. <thead>
  26. <tr>
  27. <th>Product Image</th>
  28. <th>Product Name</th>
  29. <th>Inventory Left</th>
  30. <th>Action</th>
  31. </tr>
  32. </thead>
  33. <tbody id="productTableBody">
  34. <!-- Product rows will be dynamically added here based on the selected warehouse -->
  35. </tbody>
  36. </table>
  37. </div>
  38. </div>
  39. </div>
  40.  
  41. <!-- Include Bootstrap JS and Popper.js -->
  42. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js"></script>
  43. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.11.6/umd/popper.min.js"></script>
  44.  
  45. <script>
  46. // Sample product data for different warehouses
  47. const productsByWarehouse = {
  48. warehouse1: [
  49. { name: 'Product 1', image: 'https://fastly.picsum.photos/id/0/5000/3333.jpg?hmac=_j6ghY5fCfSD6tvtcV74zXivkJSPIfR9B8w34XeQmvU', inventory: 10 },
  50. { name: 'Product 2', image: 'https://fastly.picsum.photos/id/0/5000/3333.jpg?hmac=_j6ghY5fCfSD6tvtcV74zXivkJSPIfR9B8w34XeQmvU', inventory: 5 },
  51. ],
  52. warehouse2: [
  53. { name: 'Product 3', image: 'https://fastly.picsum.photos/id/0/5000/3333.jpg?hmac=_j6ghY5fCfSD6tvtcV74zXivkJSPIfR9B8w34XeQmvU', inventory: 8 },
  54. { name: 'Product 4', image: 'https://fastly.picsum.photos/id/0/5000/3333.jpg?hmac=_j6ghY5fCfSD6tvtcV74zXivkJSPIfR9B8w34XeQmvU', inventory: 12 },
  55. ],
  56. };
  57.  
  58. // Function to populate the product table based on the selected warehouse
  59. function populateProductTable(warehouse) {
  60. const productTableBody = document.getElementById('productTableBody');
  61. productTableBody.innerHTML = ''; // Clear existing rows
  62.  
  63. const products = productsByWarehouse[warehouse];
  64. if (products) {
  65. products.forEach(product => {
  66. const row = document.createElement('tr');
  67. row.innerHTML = `
  68. <td><img src="${product.image}" alt="Product Image" width="100"></td>
  69. <td>${product.name}</td>
  70. <td>${product.inventory}</td>
  71. <td><button class="btn btn-primary">View Details</button></td>
  72. `;
  73. productTableBody.appendChild(row);
  74. });
  75. }
  76. }
  77.  
  78. // Event listener for the warehouse selector
  79. const warehouseSelector = document.getElementById('warehouseSelector');
  80. warehouseSelector.addEventListener('change', function () {
  81. const selectedWarehouse = this.value;
  82. populateProductTable(selectedWarehouse);
  83. });
  84.  
  85. // Initial population of the product table with the default selected warehouse
  86. populateProductTable(warehouseSelector.value);
  87. </script>
  88. </body>
  89. </html>
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement