Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda