Jump to content

need help getting a search bar to work


Recommended Posts

Well.... it works nicely enough, and you just need to modify your js to search all columns, rather than just the first one. Example at end.

But the rest of your code could probably use a pass through the W3 HTML checker, that was... an experience to look through. BR's, fonts and centers. Not my idea of a good time.


function myFunction() {
    var input, filter, table, tr, td, i, txtValue, show;
    input = document.getElementById("myInput");
    filter = input.value.toUpperCase();
    table = document.getElementById("myTable");
    tr = table.getElementsByTagName("tr");
    for (i = 0; i < tr.length; i++) {
      show = false;
      td = tr[i].getElementsByTagName("td");
      for(j = 0; j < td.length; j++){
        if (td[j]) {
          txtValue = td[j].textContent || td[j].innerText;
          if (txtValue.toUpperCase().indexOf(filter) > -1) {
            show = true;
      if (show) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...