1. <html>
  2. <head>
  3. <script src="clienthint.js"></script>
  4. </head>
  5. <body>
  6. <form>
  7. First Name:
  8. <input type="text" id="txt1"
  9. onkeyup="showHint(this.value)">
  10. </form>
  11. <p>Suggestions: <span id="txtHint"></span></p>
  12. </body>
  13. </html>
  1. clienthint.js
  1. var xmlHttp
  2. function showHint(str)
  3. {
  4. if (str.length==0)
  5. {
  6. document.getElementById("txtHint").innerHTML=""
  7. return
  8. }
  9. xmlHttp=GetXmlHttpObject()
  10. if (xmlHttp==null)
  11. {
  12. alert ("Browser does not support HTTP Request")
  13. return
  14. }
  15. var url="gethint.php"
  16. url=url+"?q="+str
  17. url=url+"&sid="+Math.random()
  18. xmlHttp.onreadystatechange=stateChanged
  19. xmlHttp.open("GET",url,true)
  20. xmlHttp.send(null)
  21. }
  22. function stateChanged()
  23. {
  24. if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  25. {
  26. document.getElementById("txtHint").innerHTML=xmlHttp.responseText
  27. }
  28. }
  29. function GetXmlHttpObject()
  30. {
  31. var xmlHttp=null;
  32. try
  33. {
  34. // Firefox, Opera 8.0+, Safari
  35. xmlHttp=new XMLHttpRequest();
  36. }
  37. catch (e)
  38. {
  39. // Internet Explorer
  40. try
  41. {
  42. xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  43. }
  44. catch (e)
  45. {
  46. xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  47. }
  48. }
  49. return xmlHttp;
  50. }

gethint.php

    1. <?php
    2. // Fill up array with names
    3. $a[]="Anna";
    4. $a[]="Brittany";
    5. $a[]="Cinderella";
    6. $a[]="Diana";
    7. $a[]="Eva";
    8. $a[]="Fiona";
    9. $a[]="Gunda";
    10. $a[]="Hege";
    11. $a[]="Inga";
    12. $a[]="Johanna";
    13. $a[]="Kitty";
    14. $a[]="Linda";
    15. $a[]="Nina";
    16. $a[]="Ophelia";
    17. $a[]="Petunia";
    18. $a[]="Amanda";
    19. $a[]="Raquel";
    20. $a[]="Cindy";
    21. $a[]="Doris";
    22. $a[]="Eve";
    23. $a[]="Evita";
    24. $a[]="Sunniva";
    25. $a[]="Tove";
    26. $a[]="Unni";
    27. $a[]="Violet";
    28. $a[]="Liza";
    29. $a[]="Elizabeth";
    30. $a[]="Ellen";
    31. $a[]="Wenche";
    32. $a[]="Vicky";
    33. //get the q parameter from URL
    34. $q=$_GET["q"];
    35. //lookup all hints from array if length of q>0
    36. if (strlen($q) > 0)
    37. {
    38. $hint="";
    39. for($i=0; $i<count($a); $i++)
    40. {
    41. if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
    42. {
    43. if ($hint=="")
    44. {
    45. $hint=$a[$i];
    46. }
    47. else
    48. {
    49. $hint=$hint." , ".$a[$i];
    50. }
    51. }
    52. }
    53. }
    54. //Set output to "no suggestion" if no hint were found
    55. //or to the correct values
    56. if ($hint == "")
    57. {
    58. $response="no suggestion";
    59. }
    60. else
    61. {
    62. $response=$hint;
    63. }
    64. //output the response
    65. echo $response;
    66. ?>

最新文章

  1. 关于nginx.pid丢失的解决办法
  2. Atitit 图像处理知识点 &#160;知识体系 知识图谱v2
  3. js判断访问来源
  4. MACOS无限试用Cornerstone的方法
  5. 关于android获得设备宽高
  6. docker 镜像的保存以及导入
  7. python入门总结-函数
  8. CListView虚拟列表
  9. Android 联系人信息的读取注意判断是否为NULL Android联系人的删除实质
  10. PHP提高编程效率的方法,你知道多少呢?
  11. UIimageView GIF动画
  12. hosts文件的路径
  13. UML类图的常见关系1
  14. AI 人工智能 探索 (八)
  15. 结构型---适配器模式(Adapter Pattern)
  16. mssql for xml path使用
  17. date格式互转
  18. MAVEN_day03 整合SSH框架
  19. Liunx-cp命令
  20. 2013337朱荟潼 Linux第五章读书笔记——系统调用

热门文章

  1. 安装ceilometer
  2. Exchange Server 2010安装
  3. 关于kail的远程连接
  4. Git速成学习第一课:创建版本库与版本回退
  5. 实习第一个月总结(const关键字、条件编译、volatile关键字、#和##的作用、函数指针)
  6. Fabric Raft机制理解
  7. 【Python】【demo实验32】【回文数的确认】
  8. [AHOI2017初中组]guide 题解
  9. 分词搜索 sphinx3.1.1+php+mysql
  10. python新手必躺的5大坑