title: populating from database and autofill textboxes using ajax,php
body: <p>I am facing a small problem regarding this topic.I had write a code to autofill textboxes from database values when I type a id value in the previous textfield.i.e.if I type userid,the next textfields will autofill from database without refresh in ajax and php.my problem is that I cant find the error in my code.help me to find out.Here is my code:</p>
  
  <pre><code>      **a.html**
  
       &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
      &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
        &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
       &lt;title&gt;Untitled Document&lt;/title&gt;
     &lt;script type="text/javascript"&gt;
  
     var url = "getagentids.php?param=";
  
      function handleHttpResponse() {
      if (http.readyState == 4) {
       results = http.responseText.split(",");
         document.getElementById('agfn').value = results[0];
         document.getElementById('agsal').value = results[1];
         document.getElementById('agtel').value = results[2];
         document.getElementById('agid').value = results[3];
       }
      }
  
  
      function getagentids() {
      var idValue = document.getElementById("agid").value;
      var myRandom=parseInt(Math.random()*99999999);  // cache buster
      http.open("GET", url + escape(idValue) + "&amp;rand=" + myRandom, true);
      http.onreadystatechange = handleHttpResponse;
      http.send(null);
      }
  
  
      function getHTTPObject() {
      var xmlhttp;
      /*@cc_on
       @if (@_jscript_version &gt;= 5)
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (E) {
                xmlhttp = false;
                }
            } 
       @else
        xmlhttp = false;
       @end @*/
      if (!xmlhttp &amp;&amp; typeof XMLHttpRequest != 'undefined') {
       try {
         xmlhttp = new XMLHttpRequest();
         } catch (e) {
          xmlhttp = false;
          }
         }
         return xmlhttp;
        }
  
  
    var http = getHTTPObject(); // We create the HTTP Object
  
  
   &lt;/script&gt;
      &lt;/head&gt;
  
       &lt;body&gt;
      &lt;form name="schform"&gt; 
        &lt;table&gt; 
       &lt;tr&gt; 
      &lt;td&gt;Contact ID:&lt;/td&gt; 
      &lt;td&gt;&lt;input id="agid" type="text" name="contactid" onKeyUp="getagentids();"&gt;&lt;/td&gt; 
     &lt;/tr&gt;&lt;tr&gt; 
     &lt;td&gt;Tel Number:&lt;/td&gt; &lt;td&gt;&lt;input id="agtel" type="text" name="contacttel"&gt;&lt;/td&gt; 
      &lt;/tr&gt;&lt;tr&gt;
     &lt;td&gt;Name:&lt;/td&gt; &lt;td&gt;&lt;input id="agfn" type="text" name="contactfullname"&gt;&lt;/td&gt; 
    &lt;/tr&gt;&lt;tr&gt;
   &lt;td&gt;Salutation:&lt;/td&gt; &lt;td&gt;&lt;input id="agsal" type="text" name="contactsalutation"&gt;&lt;/td&gt; 
   &lt;/tr&gt; 
   &lt;tr&gt;  &lt;td&gt;&lt;input type="reset" value="Clear"&gt;&lt;/td&gt; 
  &lt;td&gt;&lt;/td&gt; 
   &lt;/tr&gt; 
  &lt;/table&gt; 
   &lt;/form&gt;
   &lt;/body&gt;
   &lt;/html&gt;
  
  
  
    **getagentids.php**
  
          &lt;?php
  
          $link = mysql_connect('localhost', 'arbiocua_mita', 'asd123$'); 
          if (!$link) 
          {
          die('Could not connect: ' . mysql_error());
           }
           mysql_select_db('arbiocua_monomita');
  
          //$param=intval($_GET['contactid']); 
  
            if(strlen($param)&gt;0)
            { 
              $result = mysql_query("SELECT ContactFullName, ContactSalutation,   ContactTel FROM contact WHERE ContactID LIKE '$param%'"); 
                  if(mysql_num_rows($result)==1) 
                     { 
                while($myrow = mysql_fetch_array($result))
               { 
             $agentname = $myrow["ContactFullName"]; 
              $agenttel = $myrow["ContactTel"]; 
             $agentsal = $myrow["ContactSalutation"]; 
             $agentid = $myrow["ContactID"]; 
             $textout = $agentname.",".$agentsal.",".$agenttel.",".$agentid; 
             } } 
             else { $textout=" , , ,".$param; 
             } } 
          echo $textout;
  
         ?&gt;
  
  
    **database**:
  
     table name 'contact'
      ContactID   ContactFullName     ContactSalutation   ContactTel
  </code></pre>