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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

noob question, passing string to function

Status
Not open for further replies.

AlbertAguirre

Programmer
Nov 21, 2001
273
US
I wrote a function and I am passing my div layer id to it.

This works:
document.getElementById("myDivLayer").innerHTML=xmlHttp.responseText;

This does not:
document.getElementById(myDivVar).innerHTML=xmlHttp.responseText;

Why?
 
setting it to "myDivLayer"

Heres the code, simplified: THIS DOES NOT WORK

function execAjax(myDivVar){

// execute server side script
xmlHttp.onreadystatechange=function stateChanged() {
if (xmlHttp.readyState==1){
document.getElementById(myDivVar).innerHTML="html here";
}
if (xmlHttp.readyState==4){
document.getElementById(myDivVar).innerHTML=xmlHttp.responseText;
}
};

xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


However, the same code with this line does work:

document.getElementById("myDivLayer").innerHTML="html here";

Ideas?
 
It seems to me that I need to pass my var to function stateChanged? How?

Anyone?
 
I tried defining a global variable to use in the stateChanged function but no luck.

Ideas? Please? Anyone... Anyone.. Bueller... Bueller....
 
Code:
function execAjax(myDivVar){ 

// execute server side script
xmlHttp.onreadystatechange=function stateChanged([!]myDivVar[/!]) { 
                if (xmlHttp.readyState==1){ 
document.getElementById(myDivVar).innerHTML="html here";
                }
                if (xmlHttp.readyState==4){ 
document.getElementById(myDivVar).innerHTML=xmlHttp.responseText;
                }
            };

xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

Calm down dude, your post hasn't been up that long.

[monkey][snake] <.
 
Im calm.

Found it. When i call the js function I passed the var with single quotes. I changed it to double and it works now.

Js stinks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top