troubleshooting Question

Cycle through AJAX search results using downkey

Avatar of slightlyoff
slightlyoff asked on
JavaScriptAJAX
3 Comments1 Solution455 ViewsLast Modified:
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";
}

"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!
ASKER CERTIFIED SOLUTION
Kim Walker
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros