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 8404935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:43:29+00:00 2026-06-09T22:43:29+00:00

I have a search box on my site to search through a database of

  • 0

I have a search box on my site to search through a database of books. The following options are presented to the user:

  • Search Query (a text input field)
  • Where to search (a select field with the options: current, archive or all)
  • What to search for (a select field with the options: title, author, owner or reader)

As the user types input into the search field suggestions for book titles popup below like Google has when you search. I want to know how to check which option they have chosen search for (i.e. title, author, etc.) and display the suggestions accordingly.

The current code I use is as follows:

HTML

    <form method='get' action='/main'>
     <label for='search'>Search</label>
     <div style='position:relative;display:inline;'>
      <input type='text' id='search' name='search' onkeyup='showHint(this.value)' autocomplete='off'/>
      <div style='display:inline;' id='txtHint'></div>
     </div>
     <select name='searchIn'>
      <option name='searchIn' id='searchIn' value='current' selected>Current</option>
      <option name='searchIn' id='searchIn' value='archive'>Archive</option>
      <option name='searchIn' id='searchIn' value='all'>All</option>
     </select>
     <select name='searchBy' onChange='getSearchBy(this.value)'>
      <option name='searchBy' id='searchBy' value='Title' selected>By Title</option>
      <option name='searchBy' id='searchBy' value='Author'>By Author</option>
      <option name='searchBy' id='searchBy' value='Owner'>By Owner</option>
      <option name='searchBy' id='searchBy' value='Reader'>By Reader</option>
     </select>
     <input type='submit' class='submit' value='Submit'/>
    </form>

AJAX/Javascript

      function getSearchBy(val){
   return val;
  }
  function showHint(str){
   var xmlhttp;
   if (str.length==0){ 
    document.getElementById('txtHint').innerHTML='';
    return;
   }
   if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
   }
   else{// code for IE6, IE5
    xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
   }
   xmlhttp.onreadystatechange=function(){
    if (xmlhttp.readyState==4 && xmlhttp.status==200){
     document.getElementById('txtHint').innerHTML=xmlhttp.responseText;
    }
   }
   var searchBy = getSearchBy(document.getElementById('searchBy').value);
   xmlhttp.open('GET','get_hint.php?q='+str+'&searchBy='+searchBy,true);
   xmlhttp.send();
  }

The file ‘get_hint.php’ does all the processing and queries the database and returns the results as the innerHTML of txtHint element…

The getSearchBy function doesn’t seem to return ‘Author’ when the ‘By Author’ option has been selected, any ideas?

Update

I know that many of these answers may be right, but I marked the one which arrived quickest right.
Thanks for the quick response from all of you!

  • 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-09T22:43:30+00:00Added an answer on June 9, 2026 at 10:43 pm

    the problem in this line.

    document.getElementById('searchBy').value
    

    you are searching for an element with id ‘searchBy’. but the element name is searchBy not id. So please add an id=’searchBy’ for the select element. and remove id=’searchBy’ from options.

    <select name='searchBy' id='searchBy' onChange='getSearchBy(this.value)'>
          <option  value='Title' selected>By Title</option>
          <option  value='Author'>By Author</option>
          <option  value='Owner'>By Owner</option>
          <option  value='Reader'>By Reader</option>
         </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a search box on my site. The text displayed in the input
I have a search box on my site. If a student enters some text,
I have the following problem: I have a search box in which user can
I am running a live search through a text box that when a user
I have a Search box on my site and when ever the user types
I have a search box on my site, whereby the user enters a term
I have an ajax search box on my site that allows the user to
I have a search box on my site and i need to replace all
In my jsp application I have a search box that lets user to search
I have a popup search box that is shown when the user mouses over

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.