<html> <head> <script type="text/javascript"> var xmlhttp; function showHint(str) { if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } var url="gethint.asp"; url=url+"?q="+str; url=url+"&sid="+Math.random(); if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange=stateChange; xmlhttp.open("GET",url,true); xmlhttp.send(null); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.onreadystatechange=stateChange; xmlhttp.open("GET",url,true); xmlhttp.send(); } } function stateChange() { if (xmlhttp.readyState==4) { if (xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } else { alert("There was a problem in the returned data"); } } } </script> </head> <body> <h3>Start typing a name in the input field below:</h3> <form action=""> First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" /> </form> <p>Suggestions: <span id="txtHint"></span></p> </body> </html>
Your Result:
Edit the code above and click to see the result.
W3Schools.com
- Try it yourself