简体   繁体   中英

Select value which comes from database (live search)

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.

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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM