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

207
Vistas
Adding an alert that says "Not found!" if the input box on search bar is nothing

I am trying to add an alert that says "not found" when you search for nothing using a search bar that I have already programmed in JavaScript. Something like this:

if (document.getElementById('query').value = *variable for nothing*) {
alert('Not found!')
}

This is example code. Can someone give me a line of code that would do this but is functional?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is one of the few cases where the solution is to write no additional code at all!

You can examine the truthiness of the .value of your element to see if it has a value in it. That means you would check the condition:

if(document.getElementById('query').value) {

If that's truthy, then it has a value. If it's falsey then it does not have a value.

document.getElementById('test').addEventListener('click', () => {
  if (document.getElementById('query').value) {
    alert('It has a value');
  } else {
    alert('It does not have a value');
  }
});
<input id="query" type="text" />
<button id="test">Test</button>

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