Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

dynamic search bar javascript

<!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>
  <tr>
    <td>Chittagong</td>
    <td>Bangladesh</td>
  </tr>
</table>

<script>
function myFunction() {
  var input, filter, table, tr, td, i, txtValue;chichi
  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>
Comment

PREVIOUS NEXT
Code Example
Javascript :: build#configuring-commonjs-dependencie 
Javascript :: classic asp get json from file 
Javascript :: classic asp get json from url 
Javascript :: javascript array column 
Javascript :: validate form on submit 
Javascript :: js create object with keys 
Javascript :: comparing two array of objects in javascript returning differences 
Javascript :: vue js datetime convert 
Javascript :: express middleware pass parameter 
Javascript :: redux packages 
Javascript :: Multiple Slick Sliders On Same Page with same classes 
Javascript :: get static props 
Javascript :: react cdn link 
Javascript :: javascript convert array to matrix 
Javascript :: javascript base64 to length 
Javascript :: how to target an element inside of a $(this) jquery 
Javascript :: joi allow additional properties 
Javascript :: indexof javascript duplicate arrays 
Javascript :: carousel react 
Javascript :: infinit for loop js 
Javascript :: how to make a check if 50% of letters are capital in discord js 
Javascript :: projection in mongodb 
Javascript :: keyup event 
Javascript :: react bootsrap color picker 
Javascript :: how to make first letter uppercase in javascript 
Javascript :: reactjs framer motion 
Javascript :: js set iframe code 
Javascript :: vue jest run single test 
Javascript :: alert function in javascript 
Javascript :: mongoose where 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =