title: how to display database field name in auto complete text box using ajax
body: <p>I was trying to display items of a particular field by typing the first letter of the field into an autocomplete textbox.But when I type a letter into the textbox,random letters are shown.Please Help.I am new at this.
  here is my ajax code</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
    function showHint(str) {
  if (str.length == 0) { 
      document.getElementById("txtHint").innerHTML = "";
      return;
  } else {
      var xmlhttp = new XMLHttpRequest();
      xmlhttp.onreadystatechange = function() {
          if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) {
              document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
          }
      };
      xmlhttp.open("GET", "drop1.php?search=" + str, true);
      xmlhttp.send();
    }
  }
  &lt;/script&gt;
  &lt;/html&gt;
  
  &lt;div style="font:14px arial"&gt;
  
      &lt;input type="text" id="search" name="search" onKeyUp="showHint(this.value)"/&gt;
  &lt;/div&gt;  &lt;p id="txtHint"&gt;&lt;/p&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Here is the Php code</p>
  
  <pre><code>&lt;?php
  include("connection.php");
  $search=$_GET['search'];
  $query=mysql_query("select * from students WHERE name LIKE '$search%' OR name='$search'");
  while($rs = mysql_fetch_array($query)) {
  echo $rs['name'];
  }
  ?&gt;
  </code></pre>