I am very new to AJAX, and have been fiddling around with it to make some new interfaces. I have the following js code that I swiped from w3schools.com,
The body of my page looks like this,
I am trying to add another parameter to the function, so I can call the function using a different span element name. I have tried this,
the body code looks like this,
But I get a "Type Mismatch" error on the,
line. I am not sure where I am going wrong, but as I said I am very new to javascript/AJAX. Anyone know what I should do?
Thanks,
Drew
Code:
var xmlHttp
function showName(RegNo)
{
if (RegNo.length==0)
{
document.getElementById("txtHint").innerHTML=""
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="db/cli/shared/getresidentname.asp"
url=url+"?RegNo="+RegNo
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
The body of my page looks like this,
Code:
<body>
<form name="form1" id="form1">
First Name:
<input type="text" id="txt1" onBlur="showName(this.value)">
</form>
<p>First Name: <span id="txtName"></span></p>
</body>
I am trying to add another parameter to the function, so I can call the function using a different span element name. I have tried this,
Code:
var xmlHttp
function showName(RegNo,ctlName)
{
if (RegNo.length==0)
{
document.getElementById(ctlName).innerHTML=""
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="db/cli/shared/getresidentname.asp"
url=url+"?RegNo="+RegNo
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged(ctlName)
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(ctlName)
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById(ctlName).innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
the body code looks like this,
Code:
<body>
<form name="form1" id="form1">
First Name:
<input type="text" id="txt1" onBlur="showName(this.value,txtName1)">
</form>
<p>First Name: <span id="txtName1"></span></p>
</body>
But I get a "Type Mismatch" error on the,
Code:
xmlHttp.onreadystatechange=stateChanged(ctlName)
line. I am not sure where I am going wrong, but as I said I am very new to javascript/AJAX. Anyone know what I should do?
Thanks,
Drew