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

127
Visualizações
I'm having trouble with a simple search form with javascript

I know what I'm stuck with is simple.

My example is here: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_filter_list

I want to do the opposite. Nothing appears at first. They start appearing as you type the 2nd or 3rd letter in the search form. Wouldn't that be great?

Thank you for your help.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There's a couple approaches you can consider, for now I can show you a solution that only edits your current code slightly.

To better tell you what lines I've changed, I've moved your code over to a JSfiddle.

https://jsfiddle.net/ubLve2hx/1/

I've edited your code to fit the functionality you describe, it starts showing the list once you've typed 2 characters or more.

The first change is at line 5 of the HTML section;

<ul id="myUL" style="display: none;">

We've made it so your list isn't visible to begin with.

Then at the javascript section, line 8 to 12 we've added the following;

if (filter.length > 1) {
  ul.style.display = "block";
} else {
  ul.style.display = "none";
}

So if your filter has more than 1 character, show the list, else hide the list.

I hope this has helped! If you want I can show you some approaches on how to better structure search lists like this.

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