Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const searchInput = document.getElementById('searchInput');
+ const filterSelect = document.getElementById('filterSelect');
+ const table = document.querySelector('table');
+
+ function filterTable() {
+ const searchTerm = searchInput.value.toLowerCase();
+ const filterCategory = filterSelect.value;
+ const rows = table.getElementsByTagName('tr');
+
+ for (let i = 1; i < rows.length; i++) {
+ const row = rows[i];
+ const cells = row.getElementsByTagName('td');
+ let shouldShow = false;
+
+ if (filterCategory === 'all') {
+ shouldShow = Array.from(cells).some(cell =>
+ cell.textContent.toLowerCase().includes(searchTerm)
+ );
+ } else {
+ const categoryIndex = {
+ 'make': 2,
+ 'model': 3,
+ 'year': 1,
+ 'trim': 4
+ }[filterCategory];
+
+ shouldShow = cells[categoryIndex].textContent
+ .toLowerCase()
+ .includes(searchTerm);
+ }
+
+ row.style.display = shouldShow ? '' : 'none';
+ }
+ }
+
+ searchInput.addEventListener('input', filterTable);
+ filterSelect.addEventListener('change', filterTable);
+ });