Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 75964

How to hide the all the content until the user searches for a specific item in this table?

$
0
0

I want to create a table with hidden contents from the user but is available if they typed the specific items. So, basically, i just want to have a search bar as the only thing displayed.

Here is what I already have, and this is from w3schools:

<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1"><style>
    * {
      box-sizing: border-box;
    }
    #myInput {
      background-image: url('/css/searchicon.png');
      background-position: 10px 10px;
      background-repeat: no-repeat;
      width: 100%;
      font-size: 16px;
      padding: 12px 20px 12px 40px;
      border: 1px solid #ddd;
      margin-bottom: 12px;
    }
    #myTable {
      border-collapse: collapse;
      width: 100%;
      border: 1px solid #ddd;
      font-size: 18px;
    }
    #myTable th,
    #myTable td {
      text-align: left;
      padding: 12px;
    }
    #myTable tr {
      border-bottom: 1px solid #ddd;
    }
    #myTable tr.header,
    #myTable tr:hover {
      background-color: #f1f1f1;
    }</style></head><body><h2>My Customers</h2><input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name"><table id="myTable"><tr class="header"><th style="width:60%;">Name</th><th style="width:40%;">Country</th></tr><tr><td>Alfreds Futterkiste</td><td>Germany</td></tr><tr><td>Berglunds snabbkop</td><td>Sweden</td></tr><tr><td>Island Trading</td><td>UK</td></tr><tr><td>Koniglich Essen</td><td>Germany</td></tr><tr><td>Laughing Bacchus Winecellars</td><td>Canada</td></tr><tr><td>Magazzini Alimentari Riuniti</td><td>Italy</td></tr><tr><td>North/South</td><td>UK</td></tr><tr><td>Paris specialites</td><td>France</td></tr></table><script>
    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";
          }
        }
      }
    }</script></body></html>

And lastly, how would I be able to add a clickable link on an item? I've seen website with those features and I tried to find the answer on my own but can't. I'm also a beginner and have zero background in coding, although I've learned quite fast these past few weeks. So I would appreciate if you use will use words I can understand.

If you want to know what I'm gonna do with this is i'm planning to build a free books blog where people can just search their favorite author or book title and it will appear on the search bar if its available. Thanks a lot!


Viewing all articles
Browse latest Browse all 75964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>