Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8747579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:22:47+00:00 2026-06-13T12:22:47+00:00

I have a number of search/text boxes that, using AJAX, search database tables and

  • 0

I have a number of search/text boxes that, using AJAX, search database tables and place results/search suggestions in a div similar to google search. Right now other than reloading the page there is no way to empty these divs. I would like to make it so that if you backspace to make the textbox blank as in google search, the div empties out. Right now when you backspace all the way it treats it as searching on “” and returns all the results. Or alternatively let you click outside the box to empty it. Otherwise I am ending up with filled divs on the page which clutters it up. I am thinking I either need to do change query so that if the string is empty it returns nothing or something with javascript if you click outside the box the box goes empty. Thanks for any suggestion:

Here is abbreviated code:

Javascript

function getHints(str) {
...
document.getElementById("results").innerHTML=xmlhttp.responseText;//places output in results div
...
xmlhttp.open("GET","search.php?searchterm="+str,true);
xmlhttp.send();
}

html

<input type="text" id="search" onkeyup="getHints(this.value)">Search<div id="results"></div>

php

$str = $_REQUEST['str'];
$sql = "SELECT * FROM table WHERE name LIKE '%$str%'";
search database and echo out results.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:22:48+00:00Added an answer on June 13, 2026 at 12:22 pm

    Just check for an empty string and process accordingly:

    function getHints(str) {
        if (str == "") {
            document.getElementsById("results").innerHTML = "";
        }
        else {
        ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have an advanced search page that searches a number of fields in
I have a number of text input elements that when its values are changed,
I have a HTML page that contains a search box containing a number of
I have program that is used by 4000 users to search a large database
QI have a jQuery function that causes my datagrid search results to be scrollable.
Using Python, I need to search a text file for a string that/ I
I have a search screen in a Visual Basic .Net App that has text
I have a table that was doing a fine job of full-text search until
I have added Full Text Search to my sql server 2008 express database and
I have an application that does a search of our database (exposed via EF)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.