...

View Full Version : Passing AJAX function correct div name



socalconsult
08-10-2006, 06:29 PM
My HTML page has 3 divs (showtext1, showtext2, and showtext3). Depending on which radio button I select, I want to set the innerhtml for the correct div. eg if I hit radio1, I want the responding HTML to appear in showtext1. On click for the radio, I pass a parameter that gets loaded into showQuestion as the 2nd parameter.


function showQuestion(url2, str)
{

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}

var url=url2;
url=url+"?sectionid="+str;
a=str;

xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.open("POST",url,true);
xmlHttp.send(null);
}


function stateChanged2()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
// var a=1;
document.getElementById("showtext" + a).innerHTML=xmlHttp.responseText

}
}

How can I pass the value of a to stateChanged2 so that I correctly write the value to the correct div?

Thanks

socalconsult
08-10-2006, 06:35 PM
sure enough, I was able to get help. Here is the answer in case anyone is curious:


function showQuestion(url2, str, temp3)
{

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}

var url=url2;
url=url+"?sectionid="+str;


//xmlHttp.onreadystatechange=stateChanged2;
xmlHttp.onreadystatechange= function() { stateChanged2(temp3); };
xmlHttp.open("POST",url,true);
xmlHttp.send(null);
}


function stateChanged2(a)
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{

document.getElementById("showtext" + a).innerHTML=xmlHttp.responseText

}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum