Tengo dificultades para buscar números en la tabla HTML usando javascript. Lo que quiero hacer, si ingreso 500, los resultados deberían ser 500 y números que también son mayores que 500. Revisé otras preguntas de StackOverflow pero no se responde como esperaba. ¿Alguien puede ayudarme, por favor?
function myFunction(){ let filter = document.getElementById('myInput').value; let myTable = document.getElementById('myTable'); let tr = myTable.getElementsByTagName('tr'); for(var i=0; i<tr.length; i++) { let td = tr[i].getElementsByTagName('td')[0]; if(td) { let textValue = td.textContent || td.innerHTML; if(textValue >= filter ) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } } } <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%;">Number</th> <th style="width:40%;">Alphabats Code</th> </tr> <tr> <td>500</td> <td>ANAA</td> </tr> <tr> <td>520</td> <td>MNAAA</td> </tr> <tr> <td>400</td> <td>INNA</td> </tr> <tr> <td>200</td> <td>OISSS</td> </tr> <tr> <td>500</td> <td>QIIWS</td> </tr> </table>Un pequeño cambio en tu código.
if(+textValue >= +filter )Comparar valores como número en lugar de cadenas
function myFunction(){ let filter = document.getElementById('myInput').value; let myTable = document.getElementById('myTable'); let tr = myTable.getElementsByTagName('tr'); for(var i=0; i<tr.length; i++) { let td = tr[i].getElementsByTagName('td')[0]; if(td) { let textValue = td.textContent || td.innerHTML; if(+textValue >= +filter ) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } } } <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%;">Number</th> <th style="width:40%;">Alphabats Code</th> </tr> <tr> <td>500</td> <td>ANAA</td> </tr> <tr> <td>520</td> <td>MNAAA</td> </tr> <tr> <td>400</td> <td>INNA</td> </tr> <tr> <td>200</td> <td>OISSS</td> </tr> <tr> <td>500</td> <td>QIIWS</td> </tr> </table>