Hi

I have a search box which uses AJAX to query a database and return a list of suggestions to the user, it works off the "onkeyup" event on the input textbox.

Code:
 <input type="text" id="txt1" onkeyup="showHint(this.value)" />
Obviously this creates an AJAX call for every keypress the user makes and I'd like to make this more efficient by adding a short delay before the AJAX call is made.

How would I modify my code to make this happen?

JavaScript code below:

Code:
<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.asp?q="+str,true);
xmlhttp.send();
}
</script>
Thanks