I have a script which allows to retrieve Google suggestions (XML) with Javascript and output in plain HTML:
<input id='inp' /> <select id='sug' />
<script type='text/javascript'>
function el(tid) {return document.getElementById(tid);}
function addScript(u){
var head=document.getElementsByTagName('head')[0],
sc2=document.createElement('script'); sc2.src=u;
head.appendChild(sc2);
setTimeout(function(){ head.removeChild(sc2); sc2=null;}, 20000)
}//end addScript()
function suggest(data){
var sel=el("sug").options; sel.length=0;
data[1].map(function(a){return a[0];}).map(function(a,b){
sel[b]=new Option(a);
});
sel.size=data[1].length;
}//end suggeest()
el("inp").onkeyup=function(){
addScript("http://www.google.nl/complete/search?callback=suggest&q="+this.value);
}
As you can see the XML data is now a select option list. My question: How can I get this in a ul—>li HTML rather than the select option list.
AFAIK there is no standard DOM object to represent
ul / liso your “OO” way isn’t working… however, following seems to work in my FireFox browser: in the html body have a list likeand replace in JavaScript the
suggestfunction with this oneBTW add the list before the
selectelement or write it like(ie select is writen with proper end tag) otherwise the list won’t show in the page
EDIT:
Version which seems to work in IE