Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

simple search filter for table html

<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;
  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) {
      if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    }       
  }
}
</script>
Comment

simple search filter for table html

for (i = 1; i < tr.length; i++) {
    // Hide the row initially.
    tr[i].style.display = "none";

    td = tr[i].getElementsByTagName("td");
    for (var j = 0; j < td.length; j++) {
      cell = tr[i].getElementsByTagName("td")[j];
      if (cell) {
        if (cell.innerHTML.toUpperCase().indexOf(filter) > -1) {
          tr[i].style.display = "";
          break;
        } 
      }
    }
}
Comment

simple search filter for table html

function myFunction() {
  var input, filter, table, tr, td, cell, i, j;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("myTable");
  tr = table.getElementsByTagName("tr");
  for (i = 1; i < tr.length; i++) {
    // Hide the row initially.
    tr[i].style.display = "none";
  
    td = tr[i].getElementsByTagName("td");
    for (var j = 0; j < td.length; j++) {
      cell = tr[i].getElementsByTagName("td")[j];
      if (cell) {
        if (cell.innerHTML.toUpperCase().indexOf(filter) > -1) {
          tr[i].style.display = "";
          break;
        } 
      }
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: promise.all in javascript 
Javascript :: crypto js 
Javascript :: what hostings can run react js 
Javascript :: basic json syntax 
Javascript :: currency conversion to locale string js 
Javascript :: save item in array javascript 
Javascript :: leaflet update marker icon 
Javascript :: handle bar 
Javascript :: javascript sorting an array 
Javascript :: add property to object javascript 
Javascript :: amcharts 
Javascript :: how to add multiple event listener in javascript 
Javascript :: how to use cros 
Javascript :: message.channel.name.includes 
Javascript :: destructuring props in react 
Javascript :: merge two binary tree 
Javascript :: object assign in javascript 
Javascript :: set state using object 
Javascript :: react date picker 
Javascript :: jquery dialog modal on modal 
Javascript :: proxy api javascript set 
Javascript :: update nested formgroup angular 
Javascript :: listen to localstorage changes 
Javascript :: react table with styles 
Javascript :: concat keys json 
Javascript :: react useref hook 
Javascript :: eslint ignore javascript 
Javascript :: indexof javascript 
Javascript :: Number of trailing zeros of N! 
Javascript :: The toString() Method 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =