Hi Claus:
Here is the javascript. Very simple. Gt it from the w3C examples. Some small modifications only for me.
var xmlHttp
function showResult(data,searchtype,sessionid,nextef_tabno,nextaction,nextsubaction)
{
if (data.length==0)
{
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="/bin/ltrake.dbw?action=livesearch"
url=url+"&subaction="+searchtype
url=url+"&datastring="+data
url=url+"&sessionid="+sessionid
url=url+"&nextef_xtabno="+nextef_tabno
url=url+"&nextaction="+nextaction
url=url+"&nextsubaction="+nextsubaction
url=url+"&random="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
//alert(xmlHttp.responseText);
document.getElementById("livesearch").innerHTML=xmlHttp.responseText;
document.getElementById("livesearch").style.border="1px solid #A5ACB2";
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
Post by Claus MygindGreg,
The only thing you need in a standard ajax call to differentiate between IE
and the other browsers is loading the XMLHttpRequest;
if (window.ActiveXObject)
{
tempHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else if (window.XMLHttpRequest) {
tempHttp = new XMLHttpRequest();
}
Other than that what you are looking to do is just standard stuff that is
activated every time the user types in a character in the input field like
firing an event such as "onkeydown", "onkeypress" or "onkeyup"
In your server side app just use the "limit" method to limit the response to
5 or less records. Of course if you have more than 5 matching records at
the maximum length of the input field you will never see the remaining
records.
Then just display you results in hidden/visible <div> </div> section with an
absolute position (centered on the screen).
Claus