fork download
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w...content-available-to-author-only...3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://w...content-available-to-author-only...3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>無標題文件</title>
  6.  
  7. </head>
  8. <body>
  9.  
  10. <script type="text/javascript">
  11. function showHint(str)
  12. {
  13. var xmlhttp;
  14. if (str.length==0)
  15. {
  16. document.getElementById("txtHint").innerHTML="";
  17. return;
  18. }
  19. if (window.XMLHttpRequest)
  20. {// code for IE7+, Firefox, Chrome, Opera, Safari
  21. xmlhttp=new XMLHttpRequest();
  22. }
  23. else
  24. {// code for IE6, IE5
  25. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  26. }
  27. xmlhttp.onreadystatechange=function()
  28. {
  29. if (xmlhttp.readyState==4 && xmlhttp.status==200)
  30. {
  31. document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  32. }
  33. }
  34. xmlhttp.open("GET","gethint.php?q="+str,true);
  35. xmlhttp.send();
  36. }
  37. </script>
  38. <h3>Start typing a name in the input field below::</h3>
  39. <form action="">
  40. First name:<input type="text" id="txt1" name="aa" onkeyup="showHint(this.value)" />
  41. </form>
  42. <p>Suggestions:<span id="txtHint"></span></p>
  43. <?php
  44. // Fill up array with names
  45. $a[]="Anna";
  46. $a[]="Brittany";
  47. $a[]="Cinderella";
  48. $a[]="Diana";
  49. $a[]="Eva";
  50. $a[]="Fiona";
  51. $a[]="Gunda";
  52. $a[]="Hege";
  53. $a[]="Inga";
  54. $a[]="Johanna";
  55. $a[]="Kitty";
  56. $a[]="Linda";
  57. $a[]="Nina";
  58. $a[]="Ophelia";
  59. $a[]="Petunia";
  60. $a[]="Amanda";
  61. $a[]="Raquel";
  62. $a[]="Cindy";
  63. $a[]="Doris";
  64. $a[]="Eve";
  65. $a[]="Evita";
  66. $a[]="Sunniva";
  67. $a[]="Tove";
  68. $a[]="Unni";
  69. $a[]="Violet";
  70. $a[]="Liza";
  71. $a[]="Elizabeth";
  72. $a[]="Ellen";
  73. $a[]="Wenche";
  74. $a[]="Vicky";
  75.  
  76. //get the q parameter from URL
  77. $q=$_GET["q"];
  78.  
  79. //lookup all hints from array if length of q>0
  80. if (strlen($q) > 0)
  81. {
  82. $hint="";
  83. for($i=0; $i<count($a); $i++)
  84. {
  85. if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
  86. {
  87. if ($hint=="")
  88. {
  89. $hint=$a[$i];
  90. }
  91. else
  92. {
  93. $hint=$hint." , ".$a[$i];
  94. }
  95. }
  96. }
  97. }
  98.  
  99. // Set output to "no suggestion" if no hint were found
  100. // or to the correct values
  101. if ($hint == "")
  102. {
  103. $response="no suggestion";
  104. }
  105. else
  106. {
  107. $response=$hint;
  108. }
  109.  
  110. //output the response
  111. echo $response;
  112. ?>
  113. </body>
  114. </html>
Success #stdin #stdout #stderr 0.01s 20520KB
stdin
Standard input is empty
stdout
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w...content-available-to-author-only...3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://w...content-available-to-author-only...3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文件</title>

</head>
<body>

<script type="text/javascript">
function showHint(str)
{
	var xmlhttp;
	if (str.length==0)
  	{ 
  		document.getElementById("txtHint").innerHTML="";
  		return;
  	}
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		xmlhttp=new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	xmlhttp.onreadystatechange=function()
  	{
  		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	{
    	document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    	}
	}
	xmlhttp.open("GET","gethint.php?q="+str,true);
	xmlhttp.send();
}
</script>
<h3>Start typing a name in the input field below::</h3>
<form action=""> 
First name:<input type="text" id="txt1" name="aa" onkeyup="showHint(this.value)" />
</form>
<p>Suggestions:<span id="txtHint"></span></p> 
no suggestion</body>
</html>
stderr
PHP Notice:  Undefined index: q in /home/6Uk5VT/prog.php on line 77
PHP Notice:  Undefined variable: hint in /home/6Uk5VT/prog.php on line 101