Autocomplete and ajax

Autocomplete and ajax

This is where I want the autocompletion.

  1. <td>Tilf&oslash;j servicedel, varenummer:<input type="text" name="varenummer" id="varenummer" value="" onkeyup="gethint(this.value)"></td>
And here is my ajax call gethint()

  1. function gethint(str) {
  2.         if (str=="") {
  3.             document.getElementById("hint").innerHTML="";
  4.             return;
  5.         }
  6.         if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
  7.             xmlhttp=new XMLHttpRequest();
  8.         }
  9.         else {// code for IE6, IE5
  10.             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  11.         }
  12.         xmlhttp.onreadystatechange=function() {
  13.             if (xmlhttp.readyState==4 && xmlhttp.status==200) {
  14.                     document.getElementById("hint").innerHTML=xmlhttp.responseText;
  15.                 }
  16.         }
  17.         xmlhttp.open("GET","gethint.php?d="+str,true);
  18.         xmlhttp.send();
  19. }
And here is the gethint.php page.

  1. <?
  2. include 'include.php';
  3. $select2 = mysql_query("SELECT Varenum FROM Dele");
  4. // Fill up array with names
  5. while ($result = mysql_fetch_array($select2)) {
  6.     $a[]=$result['Varenum'];
  7. }
  8. //get the q parameter from URL
  9. $d=$_GET["d"];
  10. //lookup all hints from array if length of q>0
  11. if (strlen($d) > 0)
  12.   {
  13.   $hint="";
  14.   for($i=0; $i<count($a); $i++)
  15.     {
  16.     if (strtolower($d)==strtolower(substr($a[$i],0,strlen($d))))
  17.       {
  18.       if ($hint=="")
  19.         {
  20.         $hint=$a[$i];
  21.         }
  22.       else
  23.         {
  24.         $hint=$hint." <br /> ".$a[$i];
  25.         }
  26.       }
  27.     }
  28.   }
  29. // Set output to "no suggestion" if no hint were found
  30. // or to the correct values
  31. if ($hint == "")
  32.   {
  33.   $response="no suggestion";
  34.   }
  35. else
  36.   {
  37.   $response=$hint;
  38.   }
  39. //output the response
  40. echo $response;
  41. ?>
By this I can get the suggestions by writing <span id="hint"></span>
But how can I do it as a autocompletion with the jq-ui like this: autocomplete example
When $hint is a php variable and this above example is done with jq/javascript.

Any help out there?