2016-06-22 8 views
0

私は完全に機能しているスクリプトを持っていますが、値を選択してテキストフィールドに配置することはできません。データベースからの選択値(ライブ検索)

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(); 
} 

データベースからの値を選択して配置する方法を教えてください。

+0

'' livesearch' 'ですか?もしそうなら、あなたは 'innerHTML'の代わりに' value'を使う必要があります。 – gcampbell

+0

'livesearch'はデータベース@gcampbellの結果を取得するdivです –

答えて

0

私は簡単な実例を作りました。

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>

関連する問題