title: onkeyup Ajax Call and Live Search
body: <p>I using a simple ajax script which returns found records using <code>onkeyup</code> in input field.</p>
  
  <p>The problem:</p>
  
  <p>Once a record has been returned from call it will stay printed on screen no matter what input is made or if string is latered on field.</p>
  
  <p>Sample:</p>
  
  <p>Lets say the string typed on form field is the word <code>red</code>.</p>
  
  <p>red gets printed to screen.</p>
  
  <p>if the letter <code>i</code> is added after this been returned, it still shows red.
  i need it to show nothing.</p>
  
  <p>Unsure if the problem lies on the readystate.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function showResult(str)
  {
  if (str.length==0)
    {
    document.getElementById("input1").innerHTML="";
    document.getElementById("input1").style.border="0px";
    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 &amp;&amp; xmlhttp.status==200 &amp;&amp; xmlhttp.responseText!='')
      {
      document.getElementById("input1").innerHTML=xmlhttp.responseText;
      document.getElementById("input1").style.border="1px solid #A5ACB2";
      }
    }
  xmlhttp.open("GET","getajax.php?q="+str,true);
  xmlhttp.send();
  }
  &lt;/script&gt; 
  </code></pre>