I using a simple ajax script which returns found records using onkeyup
in input field.
The problem:
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.
Sample:
Lets say the string typed on form field is the word red
.
red gets printed to screen.
if the letter i
is added after this been returned, it still shows red.
i need it to show nothing.
Unsure if the problem lies on the readystate.
<script type="text/javascript">
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 && xmlhttp.status==200 && 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();
}
</script>