Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!