I am experimenting with AJAX and I am running into an issue.
On my page, I have multiple spans with a similar naming convention. eg showtext1, showtext2, showtext3. On the click of another span, I pass my AJAX functions a paramater. One of these parameters is a number that corresponds to the number following showtext. I want to pass the resulting response text to the innerhtml of the correct span.
My current code is:
id=showtext1
id=showtext2, etc.
What I want to do is on the click of a span, I call a javascript function. I pass the function a parameter called temp3 that contains an integer (1, 2, 3, etc)
Code:
function showQuestion(url2, str, temp3, temp4)
{ xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
public var a=temp3;
var url=url2;
url=url+"?id="+str;
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("POST",url,true);
xmlHttp.send(null);
}
function stateChanged2()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
b="showtext" + a;
document.getElementById(b).innerHTML=xmlHttp.responseText
}
}
I am trying to pass a public variable to my 2nd function stateChanged2 but I keep getting an error about a missing ;. If I cant set a public variable, how can I dynmically call the correct showtext span?
On my page, I have multiple spans with a similar naming convention. eg showtext1, showtext2, showtext3. On the click of another span, I pass my AJAX functions a paramater. One of these parameters is a number that corresponds to the number following showtext. I want to pass the resulting response text to the innerhtml of the correct span.
My current code is:
id=showtext1
id=showtext2, etc.
What I want to do is on the click of a span, I call a javascript function. I pass the function a parameter called temp3 that contains an integer (1, 2, 3, etc)
Code:
function showQuestion(url2, str, temp3, temp4)
{ xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
public var a=temp3;
var url=url2;
url=url+"?id="+str;
xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("POST",url,true);
xmlHttp.send(null);
}
function stateChanged2()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
b="showtext" + a;
document.getElementById(b).innerHTML=xmlHttp.responseText
}
}
I am trying to pass a public variable to my 2nd function stateChanged2 but I keep getting an error about a missing ;. If I cant set a public variable, how can I dynmically call the correct showtext span?