I am using AJAX for the first time with PHP and mySQL. I have been following some examples and tutorials on how to use AJAX with INPUT fields.
I have a form with 2 input fields.
- 1st input field: User type in 4 digits
- 2nd input field: The 4 digits are looked up in the mySQL db and outputted on this field.
Most examples are based on output in div's and span's while i am interested in output on my 2nd INPUT field.
How is this possible?
My js-file:
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","include/postalcode.php?q="+str,true);
xmlhttp.send();
}