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

141
Views
I wanted to make a search box using JavaScript. All of my codes seems perfect for me. But, it's not working properly

May be there is some silly mistake I made. It's been 2 days I can't figure out the error. Here is what I want to achieve: When I type something on my search box the blocks which matches with my search there display will be block and others display will be none. Here is my HTML below.

<form class="d-flex">
  <input id="searchInput" class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
  <button class="btn btn-outline-success" type="submit">Search</button>
</form>

Here is the JavaScript Code. The problem is actually here. From the includes part it's not working properly.:

const search = document.getElementById('searchInput');
search.addEventListener('input', function(){
    const inputValue = search.value.toLowerCase();
    const noteCard = document.getElementsByClassName('cards');
    Array.from(noteCard).forEach(function(element){
        const cardTxt = element.getElementsByTagName('p')[0].innerText;
        console.log(typeof cardTxt)
        if(cardTxt.includes(inputValue)){
            console.log("yes included");
            element.style.display = 'block';
        }
        else{
            console.log('not included')
            element.style.display = 'none';

        }
    })
})

You may think what is cards, please have a look:

let html= "";
    noteArray.forEach(function(element, index){
        html +=`
        <div class="card my-2 mx-2 cards" style="width: 18rem;">
        <div class="card-body">
          <h5 class="card-title">Note ${index + 1}</h5>
          <p class="card-text">${element}</p>
          <button id=${index} onclick="deleteNote(this.id)" class="btn btn-primary">Delete Note</button>
        </div></div>
        `;

I can't find a error. If you can figure it out. Please let me know. You may need to see the full code. Here is my codepen link: https://codepen.io/techsinkv1/project/editor/Zvdvrg

about 4 years ago · Juan Pablo Isaza
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!