RE: Re: closure and multiple frames
"Lon Boonen" <[email protected]>
| Newsgroups | gmane.comp.web.dom.wdf |
|---|---|
| Message-ID | <[email protected]> |
This is a mess. First of all install Microsoft's Debugger and try debugging your own code. Or use Mozilla's Debugger if you must. Second clickFix is getting its event from window.event. But that window is not the window where the event was fired. Third inside clickFix you can refer to 'this' to get the element that fired the event. Fourth you are boolean-comparing your zero-based index prop. Wrong because 0 is false. Fifth take small steps and check every step. The fact that you have at least four problems in your code means you've taken at least three steps too many at once. Good luck, Lon ________________________________ Van: [email protected] namens bennybobw Verzonden: ma 12-12-2005 14:42 Aan: [email protected] Onderwerp: [wdf-dom] Re: closure and multiple frames 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 > > Unsubscribe [email protected] List info http://www.quirksmode.org/dom/list.html Yahoo! Groups Links [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/