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

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

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 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!