-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrch.js
32 lines (29 loc) · 1008 Bytes
/
srch.js
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
// Get the input field and table
var srch = document.getElementById("searchInput");
var table = document.getElementById("table");
// Add an event listener to the input field
srch.addEventListener("input", function() {
var input = document.getElementById("searchInput");
// Get the filter value and convert it to lowercase
var filter = input.value.toLowerCase();
// Get the table rows
var rows = table.getElementsByTagName("tr");
// Loop through the rows and hide those that don't match the search query
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var cells = row.getElementsByTagName("td");
var match = false;
for (var j = 0; j < cells.length; j++) {
var cell = cells[j];
if (cell.innerHTML.toLowerCase().indexOf(filter) > -1) {
match = true;
break;
}
}
if (match) {
row.style.display = "";
} else {
row.style.display = "none";
}
}
});