I have a table with multiple rows and columns. I wrote a function that is currently searching through only the first and last columns of my table, however I am not sure why the middle columns are being skipped over. I tried adding another for loop and got an error.
function function2(){
var input = document.getElementById("myInput");
var filter = input.value.toUpperCase();
var table = document.getElementById("table2c");
var tr = table.getElementsByTagName("tr");
var td, tdArr, i, j;
for (i = 0; i < tr.length; i++) {
tdArr = tr[i].getElementsByTagName("td");
for (j = 0; j < tdArr.length; j++){
td = tdArr [j];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1 ) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
}
This is my table:
<table className="table table-bordered" id="table2c">
<tbody>
<tr>
<th> Header Name: </th>
<th> Description: </th>
<th> Value: </th>
</tr>
<tr>
<td> Authorization </td>
<td> security token </td>
<td> To be supplied </td>
</tr>
<tr>
<td> Content-Type </td>
<td> body of the request </td>
<td> applicaiton </td>
</tr>
<tr>
<td> API-KEY </td>
<td> ID </td>
<td> To be supplied </td>
</tr>
<tr>
<td> correlation </td>
<td> Unique identifier </td>
<td> e.g. control number </td>
</tr>
<tr>
<td> name </td>
<td> system name </td>
<td> One of: </td>
</tr>
</tbody>
</table>