I’m using the W3Schools code example. I was wondering how make it search by number for convince for the user. Could the .toUpperCase(); be causing this problem? If so what is the work around? I did try other filter techniques, but they came with the same problem.
function Search() {
// Declare variables
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("input");
filter = input.value.toUpperCase();
table = document.getElementById("table");
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
New contributor
XDW is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.