Type Ahead functionality in javascript

Hi,
I have textbox and a DIV below it to show the suggestions.

<input type="text" class="text dropdown" id="qsfield" size="45" onkeypress="closeSuggest(this);loadList();suggest(this,'dropdown',searchListDropdowns);" />
<div id="qssuggest" class="suggest"></div>

where suggest()  is the function to populate the DIV with the array values (searchListDropdowns is the array name).

My problem is, if i press a key in my text box it shows up the div, and when i press the next character it disappears and when i press the next character it appears again.

For each and every character i press it should show me the div.

here is the suggest() function.

function suggest(searchBox, thisType, thisList)
{
  if((thisType == "dropdown" && suggestBox != document.getElementById(searchBox.id.replace(/field/, "suggest")))  || (thisType != "dropdown" && searchBox.value.length > 2))
  {
    keepSuggest = false;
    _closeSuggest();
    keepSuggest = true;
    suggestBox = document.getElementById(searchBox.id.replace(/field/, "suggest"));
    suggestBox.innerHTML = "";
    suggestBox.style.width = (searchBox.offsetWidth - 2) + "Px";
    suggestBox.style.left = positionLeft(searchBox) + "Px";
    if(thisList || thisType == "dropdown")
    {  
      if(!thisList)
      { thisList = dummyDropdowns; }
      suggestWords = getSuggest('', thisList);
    }
    else
    {  suggestWords = getSuggest(searchBox.value); }
    if(suggestWords.length > 0)
    {
      suggestBox.style.display = "block";
      for(i=0; i<suggestWords.length; i++)
      {
        suggestWordHL = suggestWords[i].replace(new RegExp("(" + searchBox.value + ")", "gi"), '<strong>$1</strong>')
        suggestBox.innerHTML += "<a href=\"#" + suggestWords[i] + "\" onclick=\"takeSuggest('" + searchBox.id + "', this); return false;\">" + suggestWordHL + "</a>";
      }
      var suggestBoxBottom = suggestBox.offsetHeight + positionTop(searchBox) + searchBox.offsetHeight;
      var documentBottom = document.getElementsByTagName("body")[0].offsetHeight;
      var windowBottom = document.documentElement.scrollTop + document.documentElement.clientHeight;
      if(suggestBoxBottom > documentBottom || suggestBoxBottom > windowBottom)
      { suggestBox.style.top = (positionTop(searchBox) - suggestBox.offsetHeight) + "Px"; }
      else
      { suggestBox.style.top = (positionTop(searchBox) + searchBox.offsetHeight) + "Px"; }
    }
  }
}

where suggest(searchBox, thisType, thisList) - Searchbox is the textbox name
thisType - is 'dropdown'
thisList - is the array that holds the values to display on the DIV.

any help appreciated.

thanks,
G.
LVL 4
gcmachelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BadotzCommented:
Part of the (ugly) inline js says:

onkeypress="closeSuggest(this);

yet in the "suggest" function you say this:

_closeSuggest();

Is this correct?
0
StormjackCommented:
It looks like you're trying to reconstruct some built in functionality from the AJAX AutoCompleteExtender.  Give that a shot.
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Michel PlungjanIT ExpertCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.