Hey, I was looking through W3's tutorial on AJAX and I decided to make a javascript function that would populate a form field based on the response of a page. I took all their functions and tried to create the below one.
Can anyone see why it wont work?
function populateForm(myForm,formField,PageFrom,infoToSend)
{
var xmlHttp;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
//alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.formField.value=xmlHttp.responseText;
}
}
var url=PageFrom;
url=url+"?q="+infoToSend;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
This is how I am calling it:
<form id="qwert" name="qwert">
<input id="qwer" name="qwer" type="text" onkeyup="populateForm('qwert','qwerty','echo.php',this.value);">
<input id="qwerty" name="qwerty" type="text">
</form>