Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

72
Visualizações
Search function in PHP

I'm trying to insert a search function into my website, the one I found can find data from multiple columns (which is great) but the problem is that after the search results get displayed, The text header isn't showing (which isn't good). Does anyone know how to show the search results including the text header? I'm still new to coding, sorry.

<script>
function tableSearch() {
  
  // Declare variables 
  var input, filter, table, tr, td, i;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("T_SJSM");
  tr = table.getElementsByTagName("tr");


  // Loop through all table rows AND COLUMNS, and hide those who don't match the search query
  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td");
    var match = false;
    
    //Loop trough all columns
    for(var j = 0; j < td.length; j++) {
      if(td[j]) {
        txtValue = td.textContent || td.innerText;
        if (td[j].innerHTML.toUpperCase().indexOf(filter) > -1) {
          match = true;
        }
      }
    }
    
    //Match found in one or multiple columns
    if (match) {
      tr[i].style.display = "";
    } else {
      tr[i].style.display = "none";
    }
  }
}

</script>
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You need to skip the first row (which is the header row)

So start your loop from 1

for (i = 1; i < tr.length; i++) {
about 4 years ago · Juan Pablo Isaza Relatório

0

Your table structure should be like this

<table>
    <thead>
        <tr></tr>
    </thead>
    <tbody>
        <tr></tr>
        <tr></tr>
        <tr></tr>
        <tr></tr>
        <tr></tr>
    </tbody>
</table>

If your table is looking like this then you can change only one line like this:

tr = document.querySelector('tbody').getElementsByTagName("tr");
about 4 years ago · Juan Pablo Isaza Relatório

0

table = document.getElementById("T_SJSM");

add "T_SJSM" Id to the tbody

or start first loop (tr loop) from 1.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda