I have a text box. When I enter something into the text box, I want to load the material in the DIV below. What is my code equivalent:
<input type="text" onkeyup="/* I am not sure how it done, but I'll just write: */ document.getElementById('search_results').innerHTML = getContents('search.php?query='+this.value);" /><br/>
<div id="search_results"></div>
I hope you can help. Thanks in advance!
EDIT: I would appreciate it if the solution did not include the use of jQuery - if possible.
ANSWER: How do I do this:
<input type="text" onkeyup="loadSearchResults(this.value)" /><br/>
<div id="search_results"></div>
<script>
function loadSearchResults(query){
if (window.XMLHttpRequest){
var xmlhttp=new XMLHttpRequest();
}else{
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("search_results").innerHTML=xmlhttp.responseText;
}else if(xmlhttp.readyState>=1 && xmlhttp.status==200){
}
}
xmlhttp.open("GET","search.php?search="+query,true);
xmlhttp.send();
}
</script>
source
share