Jump to content
Sign in to follow this  
mcgufa

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.

https://validator.w3.org

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";
      }
    }       
  }

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...