I am trying to make filter that will filter based on multiple inputs. One input will filter in one column.
My JavaScript & code:
function myFunction(column, input) {
var filter, table, tr, td, i, txtValue;
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[column];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
<div class="row">
<input class="font-15 w-180-px" onkeydown="myFunction(0, this)" type="text">
<label class="font-18"> Input 1 </label>
<br>
<input class="font-15 w-180-px" onkeydown="myFunction(1, this)" type="text">
<label class="font-18"> Input 2 </label>
<br>
<input class="font-15 w-180-px" onkeydown="myFunction(2, this)" type="text">
<label class="font-18"> Input 3 </label>
<br>
<input class="font-15 w-180-px" onkeydown="myFunction(3, this)" type="text">
<label class="font-18"> Input 4 </label>
<br>
<input class="font-15 w-180-px" onkeydown="myFunction(4, this)" type="text">
<label class="font-18"> Input 5 </label>
<br>
<input class="font-15 w-180-px" onkeydown="myFunction(5, this)" type="text">
<label class="font-18"> Input 6 </label>
<br>
</div>
<table id="myTable">
<tr class="header">
<th style="width:20%;">1</th>
<th style="width:20%;">2</th>
<th style="width:20%;">3</th>
<th style="width:20%;">4</th>
<th style="width:20%;">5</th>
<th style="width:20%;">6</th>
</tr>
<tr>
<td>Some 1 - a</td>
<td>Some 2 - a</td>
<td>Some 3 - a</td>
<td>Some 4 - a</td>
<td>Some 5 - a</td>
<td>Some 6 - a</td>
</tr>
<tr>
<td>Some 1 - b</td>
<td>Some 2 - b</td>
<td>Some 3 - b</td>
<td>Some 4 - b</td>
<td>Some 5 - b</td>
<td>Some 6 - b</td>
</tr>
<tr>
<td>Some 1 - c</td>
<td>Some 2 - c</td>
<td>Some 3 - c</td>
<td>Some 4 - c</td>
<td>Some 5 - c</td>
<td>Some 6 - c</td>
</tr>
<tr>
<td>Some 1 - d</td>
<td>Some 2 - d</td>
<td>Some 3 - d</td>
<td>Some 4 - d</td>
<td>Some 5 - d</td>
<td>Some 6 - d</td>
</tr>
</table>
So basically - now I enter value in Input 1 and it filters table corectly but then I enter value into Input 2 and it filters value only for second column of table. I want to enter value into Input 1 and Input 2 and it will filter row where Input 1 and Input 2 values are contained. Thanks for any help.
btw. I dont have problem with using JQuery.