-
<%@LANGUAGE= "VBSCRIPT" CODEPAGE= "65001" %>
-
<html>
-
<head>
-
<script src= "clienthint.js"></script>
-
</head>
-
<body>
-
-
<form>
-
Enter Word:
-
<input type= "text" id= "txt1"
-
οnkeyup= "showHint(this.value)">
-
</form>
-
-
<p>Suggestions: <span id= "txtHint"></span></p>
-
-
</body>
-
</html>
JavaScript Code:
-
var xmlHttp
-
-
function showHint (str )
-
{
-
if (str. length== 0 )
-
{
-
document. getElementById ( "txtHint" ). innerHTML= "";
-
return;
-
}
-
xmlHttp=GetXmlHttpObject ( )
-
if (xmlHttp== null )
-
{
-
alert ( "Your browser does not support AJAX!" );
-
return;
-
}
-
var url= "gethint.asp";
-
url=url+ "?q="+str;
-
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" ). 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;
-
}
ASP Code:
-
<%@LANGUAGE= "VBSCRIPT" CODEPAGE= "65001" %>
-
<%
-
response. expires=- 1
-
Dim rsWords
-
Dim rsWords_numRows
-
Dim q
-
Dim hint
-
q= ucase ( request. querystring ( "q" ) )
-
hint= ""
-
Set rsWords = Server. CreateObject ( "ADODB.Recordset" )
-
rsWords. ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server. MapPath ( "db_hint_words.mdb" )
-
rsWords. Source = "SELECT * FROM TBL_WORDS WHERE (word LIKE'" + q + "%') ORDER BY WORD"
-
rsWords. CursorType = 2
-
rsWords. CursorLocation = 2
-
rsWords. LockType = 3
-
rsWords. Open ( )
-
rsWords_numRows = 0
-
-
If Not rsWords. EOF Then
-
Do While Not rsWords. EOF
-
If trim (hint ) = "" Then
-
hint = rsWords ( "word" )
-
Else
-
hint = hint & " , " & rsWords ( "word" )
-
End If
-
rsWords. MoveNext ( )
-
Loop
-
End If
-
if trim (hint )= "" then
-
response. write ( "no suggestion" )
-
else
-
response. write (hint )
-
end if
-
-
rsWords. Close ( )
-
Set rsWords = Nothing
-
%>
from: http://forums.aspfree.com/code-bank-54/auto-suggest-form-199141.html