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:
"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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I forgot to mention that function is attached to a "keyup" event on the search field.
ASKER
Thank you! I think that should do the trick. I appreciate you taking the time to help :)