Search in html table javascript

How to search in a html table using javascript only.

How to search in multiple tables in a html document. Using JavaScript only. This script looks at what you type in the input field. And if something changes there. Then it calls the search function of the JavaScript.

The search script simply reads every cell of the 2 tables. And if the content doesn’t contain what you typed, it will be made invisible.

When making this invisible, the first row of each table is skipped. (These are the headings, and I want to keep seeing them.)

I thought it would be nice to have a delete button as well. But that gave a problem at first. Namely, the entry field was cleared, but the table did not recover. With the button you can only call up 1 function. But then I thought of it, you can of course call up a second function from that function 😎

Search in html table – test :

Search / zoek :

Table 001

Table 002

Search javascript – source code

I do not use the CSS code in the example above, because this does not match the layout of my website 🙂 You can see the result in the video. (YouTube) below the article.

Of course, for such a small table this makes little sense. But it is for example applied in my Dutch calorie table of more than 1400 products. And then this is useful. 🙂

    How to search in multiple tables in a html document.
    Using Javascript only !!!
    The CSS is extra just to make it look better :-)
    Copyright (c) - Bruno Stroobandt.
            background-color: lightgrey;
            width: 300px;
            border: 15px solid green;
            padding: 50px;
            padding-left: 5px;
            margin: 20px;}
        #tabel{background-color: lightgrey;
            width: 300px;
            border: 15px solid green;
            padding: 50px;
            margin: 20px;}
<div id="zoekbalk">
Search / zoek : <input id='myInput' onkeyup='searchTable()' type='text'>
<button onclick="CeS()">Clear input field</button><br>
<div id="tabel">
<br>Table 001<hr>
<table id='myTable1'>
</table><hr><br>Table 002<hr>
<table id='myTable2'>
<script>function CeS(){document.getElementById('myInput').value = '';searchTable();}
function searchTable() {
    var input, filter, found, table, tr, td, i, j,tname,k;
    input = document.getElementById("myInput");
    filter = input.value.toUpperCase();
    table = document.getElementById(tname);
    tr = table.getElementsByTagName("tr");
    for (i = 0; i < tr.length; i++) {
        td = tr[i].getElementsByTagName("td");
        for (j = 0; j < td.length; j++) {
            if (td[j].innerHTML.toUpperCase().indexOf(filter) > -1) {
                found = true;
        if (found) {
            tr[i].style.display = "";
            found = false;
        } else {
            if (i>0) { //this skips the headers
            tr[i].style.display = "none";

On this site you will find more articles about javascript, but also other programming languages. Some with a useful purpose. But also simple games for fun. (Games can also be useful 🙂 and especially if you program them yourself. You are never too old to learn. 😎

English infonosity index page