Avatar of slightlyoff
slightlyoff
 asked on

Cycle through AJAX search results using downkey

I'm having issues figuring a way to cycle through results returned as part of an ajax search.
When someone presses a key, the .asp page runs SQL against the database and returns the results inside a <div>.

At this point, I'd like to be able to use the down key to go through the list, but I'm not sure how.

Here's my code:
      
if (document.getElementById('searchText').value == ""){
		 document.getElementById("search_suggest").innerHTML="";
	 }
	 if (str.length==0)
	   { 
	 	document.getElementById("search_suggest").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('search_suggest').style.display="block";
		 var ss = document.getElementById('search_suggest')		
		 ss.innerHTML = '';		
		 ss.innerHTML = xmlhttp.responseText;		
		 		
		 
		 //document.getElementById("search_suggest").innerHTML=xmlhttp.responseText;
		 }
	   }
	 xmlhttp.open("GET","showsearchresults_home.asp?"+str,true);
	 xmlhttp.send();
	
}

//Mouse over function
function suggestOver(div_value)
 {	
 	div_value.className = 'suggest_link_over';
 }
 
//Mouse out 
function suggestOut(div_value) 
 {	
	div_value.className = 'suggest_link';

} 
  
//Click function
function setSearch(value) 
{	
document.getElementById('searchText').value = value;	
document.getElementById('search_suggest').innerHTML = '';
document.getElementById('search_suggest').style.display="none";
}

Open in new window


"search_suggest" is the ID of the DIV where the results are displayed, right under the text box where the search text is entered.

I hope this makes sense what I'm asking.
Any help would be appreciated!
JavaScriptAJAX

Avatar of undefined
Last Comment
slightlyoff

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Kim Walker

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Kim Walker

I forgot to mention that function is attached to a "keyup" event on the search field.
slightlyoff

ASKER
Thank you! I think that should do the trick.  I appreciate you taking the time to help :)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck