Classic ASP/AJAX - Auto Suggest Form

Original - ASP Code
 
 
  1. <%@LANGUAGE= "VBSCRIPT" CODEPAGE= "65001" %>
  2. <html>
  3. <head>
  4. <script src= "clienthint.js"></script>
  5. </head>
  6. <body>
  7.  
  8. <form>
  9. Enter Word:
  10. <input type= "text" id= "txt1"
  11. οnkeyup= "showHint(this.value)">
  12. </form>
  13.  
  14. <p>Suggestions: <span id= "txtHint"></span></p>
  15.  
  16. </body>
  17. </html>


JavaScript Code:
 
 
  1. var xmlHttp
  2.  
  3. function showHint (str )
  4. {
  5. if (str. length== 0 )
  6.   {
  7.   document. getElementById ( "txtHint" ). innerHTML= "";
  8.   return;
  9.   }
  10. xmlHttp=GetXmlHttpObject ( )
  11. if (xmlHttp== null )
  12.   {
  13.   alert ( "Your browser does not support AJAX!" );
  14.   return;
  15.   }
  16. var url= "gethint.asp";
  17. url=url+ "?q="+str;
  18. url=url+ "&sid="+Math. random ( );
  19. xmlHttp. onreadystatechange=stateChanged;
  20. xmlHttp. open ( "GET",url, true );
  21. xmlHttp. send ( null );
  22. }
  23.  
  24. function stateChanged ( )
  25. {
  26. if (xmlHttp. readyState== 4 )
  27. {
  28. document. getElementById ( "txtHint" ). innerHTML=xmlHttp. responseText;
  29. }
  30. }
  31.  
  32. function GetXmlHttpObject ( )
  33. {
  34. var xmlHttp= null;
  35. try
  36.   {
  37.   // Firefox, Opera 8.0+, Safari
  38.   xmlHttp= new XMLHttpRequest ( );
  39.   }
  40. catch (e )
  41.   {
  42.   // Internet Explorer
  43.   try
  44.     {
  45.     xmlHttp= new ActiveXObject ( "Msxml2.XMLHTTP" );
  46.     }
  47.   catch (e )
  48.     {
  49.     xmlHttp= new ActiveXObject ( "Microsoft.XMLHTTP" );
  50.     }
  51.   }
  52. return xmlHttp;
  53. }


ASP Code:
 
 
  1. <%@LANGUAGE= "VBSCRIPT" CODEPAGE= "65001" %>
  2. <%
  3. response. expires=- 1
  4. Dim rsWords
  5. Dim rsWords_numRows
  6. Dim q
  7. Dim hint
  8. q= ucase ( request. querystring ( "q" ) )
  9. hint= ""
  10. Set rsWords = Server. CreateObject ( "ADODB.Recordset" )
  11. rsWords. ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server. MapPath ( "db_hint_words.mdb" )
  12. rsWords. Source = "SELECT *  FROM TBL_WORDS  WHERE (word LIKE'" + q + "%') ORDER BY WORD"
  13. rsWords. CursorType = 2
  14. rsWords. CursorLocation = 2
  15. rsWords. LockType = 3
  16. rsWords. Open ( )
  17. rsWords_numRows = 0
  18.  
  19. If Not rsWords. EOF Then
  20.     Do While Not rsWords. EOF
  21.         If trim (hint ) = "" Then
  22.             hint = rsWords ( "word" )
  23.         Else
  24.             hint = hint & " , " & rsWords ( "word" )
  25.         End If
  26.         rsWords. MoveNext ( )
  27.     Loop
  28. End If
  29. if trim (hint )= "" then
  30.   response. write ( "no suggestion" )
  31. else
  32.   response. write (hint )
  33. end if
  34.  
  35. rsWords. Close ( )
  36. Set rsWords = Nothing
  37. %>



from: http://forums.aspfree.com/code-bank-54/auto-suggest-form-199141.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值