-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchScript.js
38 lines (32 loc) · 1.08 KB
/
searchScript.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
33
34
35
36
37
38
function searchFunction() {
// Declare variables
var i, i2, tds;
var input = document.getElementById("searchInput");
input = input.value;
input = input.replace(/[^a-zA-Z]/g, ''); // Leave only alphabetic characters
var filter = input.toUpperCase();
var table = document.getElementById("pricesTable");
var trs = table.tBodies[0].getElementsByTagName("tr");
var tdInnerText;
var count = 0;
// Loop through first tbody's rows
// Skip headers row
for (i = 1; i < trs.length; i++) {
// define the row's cells
tds = trs[i].getElementsByTagName("td");
// hide the row
trs[i].style.display = "none";
// loop through row cells
for (i2 = 0; i2 < tds.length; i2++) {
tdInnerText = tds[i2].innerHTML;
// if there's a match
if (tdInnerText.toUpperCase().indexOf(filter) > -1) {
// show the row
trs[i].style.display = "";
count++;
// skip to the next row
continue;
}
}
}
}