lloydie11
New Coder
Hi,
I'm using the below code to filter a web dataset, which the first Column, and First Row are both defined as a header (TH),
This works in practice, and i get my results, but as it's also classifying my first header as a filterable object, i loose my top header, any ideas how i could change this so it still includes the first row/header in the outputted results,
Thanks,
I'm using the below code to filter a web dataset, which the first Column, and First Row are both defined as a header (TH),
This works in practice, and i get my results, but as it's also classifying my first header as a filterable object, i loose my top header, any ideas how i could change this so it still includes the first row/header in the outputted results,
JavaScript:
<script>
function myFunction() {
var input, filter, table, tr, td, th, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("th")[0];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
Thanks,