onkeyup Ajax Call and Live Search

elissagseveds

New Member
I using a simple ajax script which returns found records using \[code\]onkeyup\[/code\] 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 \[code\]red\[/code\].red gets printed to screen.if the letter \[code\]i\[/code\] is added after this been returned, it still shows red.i need it to show nothing.Unsure if the problem lies on the readystate.\[code\]<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> \[/code\]
 
Back
Top