Re: closure and multiple frames

"bennybobw" <[email protected]>
Newsgroups gmane.comp.web.dom.wdf
Message-ID <[email protected]>
Okay, I've changed onMouseClick to onclick (that somehow got changed 
when I rewrote the code).  I put in this new code, but when I put 
alert(srcEl) in clickFix, it returns the error message "index is null 
or not an object."  I think part of the problem is that I can't 
directly pass the variable to clickFix--that is, if I put brackets in 
the onclick declaration, the function is executed and the result is 
registered to onclick.  I have to access the variable from the 
clickFix function, which is outside the for loop.  The new code looks 
like this (but it doesn't work).


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


function clickFix(e) {
    var srcEl =window.event?window.event.srcElement:e?e.target:null;
    alert(srcEl.index);
    while(srcEl && !srcEl.index) srcEl = srcEl.parentNode;
    if(!srcEl) return;
    printResponsibilities(srcEl.index);
}

Thanks,
bennybobw


--- In [email protected], Pavel Dudrenov <dudrenov@g...> wrote:
>
> This is wrong:
> 
> function clickFix() {
> 
>        printResponsibilities(this.index);
> }
> 
> The this keyword might not be what you think it is. Not all browsers
> pass this as the element on a event. This should work though:
> 
> function clickFix(e) {
>        var srcEl = window.event?window.event.srcElement:e?
e.target:null;
>        while(srcEl && !srcEl.index) srcEl = srcEl.parentNode;
> 
>         if(!srcEl) return;
> 
>        printResponsibilities(srcEl.index);
> }
> 
> Also change the .index property to some other name there might be an
> element that already has index property.
> 
> Hope that helps,
> Pavel
> 
>





------------------------ 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.