0

I have a script which is working perfectly but i am not enable to select a value and place it in text field.

function showResult(str) 
{
  if (str.length==0) 
  {
    document.getElementById("livesearch").innerHTML="";
    document.getElementById("livesearch").style.border="0px";
    document.getElementById("livesearch").style.backgroundColor="transparent";
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("livesearch").innerHTML=xmlhttp.responseText;
  document.getElementById("livesearch").style.border="1px solid #A5ACB2";
  document.getElementById("livesearch").style.backgroundColor="#FFF";
 }
 }
     xmlhttp.open("GET","getRecord.php?q="+str,true);
     xmlhttp.send();
}

please tell me how to select and place that value which comes from database.

1 Answers1

0

I made a simple working example.

var livesearch = document.getElementById("livesearch");

showResult('My text');

function showResult(str) {

  setTimeout(function(){
      livesearch.innerHTML = str;
      livesearch.style.border = "1px solid #A5ACB2";
      livesearch.style.backgroundColor = "#FFF";
  }, 1500);

}
<div id="livesearch"></div>
Stubbies
  • 3,054
  • 1
  • 24
  • 33