closure and multiple frames

"bennybobw" <[email protected]>
Newsgroups gmane.comp.web.dom.wdf
Message-ID <[email protected]>
I think that I have a closure problem but I am not sure because I don't totally understand the concept.  I am starting a loop, creating a new div and a new link in a specified iframe, and setting an onClick event to the link.  The onClick is assigned an outide function that needs the corresponding count variable to work correctly.  I've read this post,  and changed my code accordingly.  The resulting code looks like this:

for (j=0;j<resp.length;j++) {
    ...
    var newDiv=currentDoc.createElement('div');
    var newAnchor=currentDoc.createElement('a'); //currentDoc is set to the target iframe.document
    newAnchor.innerHTML=resp[j].firstChild.nodeValue;
    newAnchor.index=j;
    newAnchor.onMouseClick= clickFix;
    ... //append the anchor to the div, append div to body, etc.
}

    
function clickFix() {
        printResponsibilities(this.index);
   }

The code works correctly (all the links are created in the iframe), except I found that this.index is undefined. So I thought that maybe anchors don't have indexes so I moved index to newDiv.index=j;  Still I find that this.index is undefined.

Then I thought I might see if I could call call a different function with my onMouseClick.  I changed clickFix() to this:


function clickFix() {
        alert("Hello");
   }


When I click the new links, nothing happens.  So I decided to see if the onMouseClick is getting assigned correctly.  In the loop, after assigning the onMouseClick, I put a line alert(newAnchor.onMouseClick);.  Each time the for loop returns the following in the alert box:


function clickFix() {
        alert("Hello");
   }


So it looks like it is assigning it correctly, but nothing happens when I click the created links!  So basically I have three problems:
1) I cannot pass the count variable to another function
2) The onMouseClick event is not working
3) The new link is created in an iframe, but its onClick will need to call a function outside of the iframe.  How do I set the onClick so that it will do this?
I'd be grateful for any help that anyone can give me on this.  

Oh also, I know the printResponsibilities function is working correctly because if I put:
newAnchor.onMouseClick= printResponsibilities(j);
it works correctly, but of course, this fires the function with the last j value, instead of setting the onClick event.




[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get fast access to your favorite Yahoo! Groups. Make Yahoo! your home page
http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/9rHolB/TM
--------------------------------------------------------------------~-> 

Unsubscribe
[email protected]

List info
http://www.quirksmode.org/dom/list.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/wdf-dom/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.