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

171
Vistas
Search button wont use onclick

I have this js file coded and when I try to call to my search button, nothing happens when I click the button! No error or anything just a clickable button. Any help? index.hbs my search bar and button

input type="text" id="search-text" placeholder="Search.." name="search">
  <button type="submit" id="search-button"><i class="fa fa-search" id="search-button"></i></button>
            

frontend.js

function executeSearch(){
    let searchTerm= document.getElementById('search-text').value;
    if(!searchTerm){
        location.replace('/');
        return;
    }
    let mainContent= document.getElementById('main-content');
    let searchUrl = `/posts/search?search=${searchTerm}`;
    fetch(searchUrl)
    .then((data) =>{
        console.log(data);
    })
    .catch((err) =>console.log(err));
}

const {execute} = require("../../config/database");

let searchButton = document.getElementById('search-button');
if(searchButton){
    searchButton.onclick = executeSearch;
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

im starting with this. Sorry if i could not help. Instead of this:

if(searchButton){
    searchButton.onclick = executeSearch;
}

you could try:

searchButton.addEventListener('click',executeSearch());

Im editing this because looking to the previous comment i think im wrong understanding your problem but im leaving this here maybe help somebody.

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