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

292
Views
Vanilla Javascript: How do I create a working searchbar with hidden results?

I am pretty new to Javascript and have been using it for almost a month. I am trying to create a website easter egg that can be found by typing a hidden word into the searchbar. My problem mostly has to do with making the variable value read the strings in the array. There were no error messages that popped up.

Here is my code:

let searchResults = ['dog', 'cat', 'bird'];
let searchInput = document.querySelector('.search-box .input-box #searchbar');

function searchBar() {
  searchInput.addEventListener("keyup", function(event) {
    if (event.keyCode == 13) {
    } else {
    }
    });
  searchInput.addEventListener("input", function(event) {
    let value = event.target.value;
    if (value == searchResults[2] && (event.keyCode == 13)) {
      window.location.href = "bird.html";
    } else {
    }
  });
}

There is also a small additional issue with the keycode firing off multiple times. I'm not too worried about this, but it would be nice to find a solution for it.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There is no "keyCode" property for an input event. The keyCode exists only on keyboard events, but input is it's own, separate type of event.

Use the keyup event instead. There's really no reason to have two separate event handlers anyway.

let searchResults = ['dog', 'cat', 'bird'];
let searchInput = document.querySelector('#searchbar');


searchInput.addEventListener("keyup", function(event) {
  if (event.keyCode == 13) {
    
    let value = event.target.value;
    if(value == searchResults[2]){
    
      // window.location.href = "bird.html";
      console.log("birb");
    
    }else{
    
      // User hit enter but it wasn't bird...
    }
    
  }
});
<input id=searchbar>

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!