I want to program a js function that allows me to search in a table. I want to show only those rows , that contain the search text in any of the
While I was able to make it work for a specific column only, I did not succeed for an entire row. So I guess it is somewhere in the inner for loop. Any idea where I am doing it wrong?
Thanks for your support! Here is my code:
function myFunction() {
var input, filter, table, tr, td, i, txtValue, allText, j;
input = document.getElementById("ipt-Search"); //my input text field where I enter the search term
filter = input.value.toUpperCase();
table = document.getElementById("tbl-RS"); // the table I want to search and filter
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
allText = "";
for (j = 0; j < tr.cells.length; j++) {
td = tr[i].getElementsByTagName("td")[j];
if (td) {
allTest = all Test + " " + td.textContent || td.innerText;
}
}
if (allText.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}