PDA

View Full Version : Auto Suggestion from an access database



tufanayd
01-22-2009, 02:13 AM
hi,
Iam trying to auto suggest names from an access database using ASP, i found some codes and customize them to my needs. Basically there is a database which contains all the names, a search form for the client to do the search. there is a span whih shows the results (suggestions) from the database, my question is if there is no record in the database i want this span to be invsible and other thing is; if the user clicks anywhere in the page again the span(suggestions) becomes invisible, below are the codes of Javascript file and the file which contains the form. I didn't post the file(gethint.asp) which we list the records from the access database in SPAN.

JAVASCRIPT FILE: (clienthint.js)

var xmlHttp

function showHint(str, box, thisForm, autoSubmit)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
document.getElementById("txtHint").style.display = "none";
return;
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="gethint.asp";
url=url+"?q="+str;
url=url+"&b="+box;
url=url+"&f="+thisForm;
url=url+"&a="+autoSubmit;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").style.display = "block";
document.getElementById("txtHint").style.background = "#EEEEEE";
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;

}
}

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;
}

function setTextBox(thisText,thisBox,thisForm,autoSubmit){
document.getElementById(thisBox).value = thisText
document.getElementById("txtHint").style.display = "none";
}



FORM FILE:

<script src="clienthint.js"></script>
<form name="form1" action="clientdetail.asp" method="post">
<table border="0" cellpadding="0" cellspacing="0" align="center" id="suggestiontable">
<tr>
<td width="95">Search Client:</td>
<td width="360"><input type="text" size="55" name="txt1" id="txt1" onKeyUp="showHint(this.value,'txt1','form1',true)"></td>
<td width="50"><input type="submit" name="submit" value="submit"></td>
</tr>
<tr>
<td></td>
<td colspan="2" id="liste"><div><span id="txtHint" class="suggest"></span></div></td>
</tr>
</table>
</form>