<spivee@gmail.com> wrote in message
news:1138655481.189933.111070@g43g2000cwa.googlegroups.com...
> Okay, I'm really new to javascript and the DOM... This isn't a
> functional script. I'm not trying to DO anything, just messing around
> to see how things work...
>
> I'm trying to call an onMouseOver event, and pass it an element id
> (assigned to a DIV element) and a URL, then have my javascript make a
> request to the server and retrieve a text document. For some reason,
> the first method I pass the variable to can call the
> document.getElementById(id) function without problems. But when I try
> to pass that 'id' variable to another method, it then sees that
> variable as 'undefined'.
>
> Here's my code...
>
> the html tag...
>
> <a href="#" id="myHref"
> onMouseOver="doGetUrl('myTest','my.txt')">change content</a><br>
> <div id="myTest"></div>
>
> The first method...
>
> function doGetUrl(id,url) {
> var http = createRequestObject();
> sendRequest(url);
> // this changes the div element's contents just fine
> document.getElementById(id).innerHTML = id;
> handleResponse(id);
> }
>
> The second method...
>
> function handleResponse(id) {
> // this errors out saying getElementById(id) is undefined.
> document.getElementById(id).innerHTML = 'changed';
> // if I just print the value of 'id' it shows as undefined
> // document.write("id="+id);
> // I do more stuff here to set the inner html for the
> // myTest div to the contents of the txt file
> // if I do document.getElementById('myTest').innerHTML here,
> // it works fine... rest of my code not really relevant here
> // ... i think...
> ....
> }
>
> It seems to me that the variable isn't being passed to the second
> function correctly. I'm not understanding why.
>
I didn't have your problem -- after commenting out:
var http = createRequestObject();
sendRequest(url);
But why would you assign two values to the same item?
document.getElementById(id).innerHTML = id;
document.getElementById(id).innerHTML = 'changed';
Received on Tue Feb 7 21:27:56 2006