Search and exclude rows in HTML table

I have a HTML table with over a thousand rows and it’s only getting bigger.
I use this function to search the data in the table.

function myFunction() {
  var input, filter, table, tr, td, 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("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";
      }
    }
  }
}

and an input box of

<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">

This works fine, I can find whatever I type in the box.
But I need another input box, or at least another way, to be able to exclude (hide) rows from the results of the search and also hide rows from the whole table.

So in the first input field I search for COKE and I get:

COKEC001-PAVM-NYC
COKEC001-PAVM-LON
COKEC001-ABCD-NYC
COKEC001-ABCD-LON
COKEC001-ABCD-LON
COKEC002-ABCD-NYC
COKEC002-ABCD-LON
COKEC002-ABCD-LON

now I want to narrow that down to only LON, so I want to be able to type NYC into the Exclude input field. So basically the search is for COKE but not NYC.

Another example is searching for version numbers, search for 8.1 but not 8.1.17 .. that would return rows with 8.1, 8.1.2, 8.1.15, 8.1.18 … many possibilities, but not 8.1.17 … all those rows would be hidden.

So my feeling is there should be a search input field and an exclude input field that can work combined together.

I’m not well versed in javascript. Any help and ideas would be much appreciated.

217 thoughts on “Search and exclude rows in HTML table”

  1. I have been surfing online more than three hours today,
    yet I never found any interesting article like yours.
    It’s pretty worth enough for me. In my view, if all webmasters and bloggers made good content as you did, the web will be much more
    useful than ever before.

    Reply
  2. I will right away clutch your rss feed as I can not find your e-mail subscription link or e-newsletter service.
    Do you have any? Kindly permit me know so that I could subscribe.
    Thanks.

    Reply
  3. It’s appropriate time to make some plans for the
    future and it’s time to be happy. I’ve learn this publish and
    if I could I want to recommend you some fascinating
    things or tips. Perhaps you could write next articles referring to this article.
    I want to learn more things approximately it!

    Reply
  4. I drop a comment each time I appreciate a post on a blog
    or if I have something to valuable to contribute
    to the discussion. It’s a result of the passion communicated in the article I read.
    And after this post The Growing Trends in Content Theft: Image Theft, Feed Scraping, and Website Hijacking ?
    Lorelle on WordPress. I was excited enough to leave
    a thought 😉 I do have a couple of questions for you
    if you usually do not mind. Could it be simply me or does it
    look like like a few of the comments appear like written by
    brain dead visitors? 😛 And, if you are writing on other sites, I’d like to keep up with everything new you have to post.
    Could you make a list all of your communal sites like your twitter feed, Facebook page or linkedin profile?

    Reply
  5. I will right away snatch your rss feed as I can’t to find your e-mail subscription link
    or newsletter service. Do you’ve any? Please let me realize
    in order that I may subscribe. Thanks.

    Reply
  6. It is the best time to make a few plans for the future and it is time to be happy.
    I’ve read this submit and if I could I wish to suggest you
    few attention-grabbing things or tips. Maybe you can write next articles regarding this
    article. I wish to read more things approximately it!

    Reply
  7. Hi there, i read your blog from time to time and i own a similar one and i
    was just curious if you get a lot of spam responses?
    If so how do you stop it, any plugin or anything you can advise?
    I get so much lately it’s driving me mad so any assistance is very much appreciated.

    Reply
  8. I’ve been surfing online more than three hours as of late, yet I never discovered
    any attention-grabbing article like yours. It is beautiful price enough for me.
    In my opinion, if all webmasters and bloggers made just right content as
    you did, the web will be a lot more useful than ever before.

    Reply
  9. Hi there, i read your blog from time to time and i own a similar one and i was just curious if you get a lot of spam responses?
    If so how do you stop it, any plugin or anything you can recommend?
    I get so much lately it’s driving me mad so any help is very much appreciated.

    Reply
  10. It is appropriate time to make some plans for the future and it’s time to be happy.
    I have read this post and if I could I want to suggest you few interesting things or advice.

    Maybe you could write next articles referring to this article.
    I desire to read more things about it!

    Reply
  11. Pingback: viagra buy online
  12. Pingback: generic viagra
  13. Pingback: buyviagraonlineny
  14. Pingback: cialis india
  15. Pingback: cheap viagra
  16. I’ve been browsing on-line greater than three hours these days, but I never found any fascinating
    article like yours. It is pretty value sufficient
    for me. In my view, if all web owners and bloggers made just right content material as you did,
    the web will likely be much more useful than ever before.

    Reply
  17. Pingback: viagra 100mg
  18. Pingback: cialis 5 mg tablet
  19. Pingback: female viagra
  20. Greetings from Idaho! I’m bored to tears at work so I decided to
    browse your site on my iphone during lunch break. I really like the
    info you present here and can’t wait to take a look when I get home.
    I’m surprised at how fast your blog loaded on my mobile ..
    I’m not even using WIFI, just 3G .. Anyways, superb blog!

    Reply
  21. Pingback: buy cialis 20mg
  22. Pingback: tadalafil liquid
  23. Pingback: viagra pour homme
  24. Pingback: sildenafil 50mg
  25. Pingback: herb viagra
  26. Pingback: lady viagra doctor
  27. Pingback: viagra vs cialis
  28. Pingback: sildenafil
  29. Pingback: viagra foods
  30. Pingback: sildenafil viagra
  31. Pingback: viagra generico
  32. Pingback: buy viagra online
  33. Pingback: natural viagra
  34. Pingback: cialis medication
  35. i need a loan desperately today, need a loan but my credit is bad. i need consolidation loan need loan [url=https://ineedloan.me/#ineedloan]need a loan fast[/url] i need a loan now with poor credit, money 3 payday loans, cash advance loans, cash advance, cash advance payday loans. Bank lending to business, terms of credit.

    Reply

Leave a Comment