Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing var to function via onreadystatechange

Status
Not open for further replies.

tokatrash

Programmer
Jan 3, 2009
1
Hi all,

First of all, I know that you have probably seen this question before. I have read the answers, but is not able to see what I am doing wrong within my code.

What I am trying to do is to pass a variable holding the name of a element id I would like to change.

Hope that you are able to point out what i am doing wrong!
Thanks a lot!!

Here is the code:
------------------------------------------------------------
var xmlHttp
function dom_seek(str, str_name)
{
if (str.length==0)
{
document.getElementById(str_name).innerHTML="";
return;
}
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="dom_status.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange = function(str_id) {
return function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById(str_id).innerHTML=xmlHttp.responseText;
}
}
}(str_name);
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
------------------------------------------------------------
 
Where does str_id come from. Do you maybe mean str_name?

Scott Prelewicz
Web Developer
COMAND Solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top