[Javascript] Evaluating an element in a function declaration, not at run time.

Ian Skinner ian.skinner at bloodsource.org
Fri Oct 1 14:45:55 CDT 2004


Hopefully this is an easy one, but I'm not sure how to describe it concise enough to Google.
 
I have the following bit of JavaScript:
 
node.childNodes[0].onclick=function()
{
       showHideAllDivs
      (
            navRoot.parentNode.id,
            this.innerHTML.replace(/[^A-Za-z]/g,""),
            this.id
      );
      return false;
} [white space modified for e-mail]
 
This dynamically assigns a function call to the onClick event of several anchor tags for some DHTML shenanigans.  
 
The trouble is that the first parameter of the showHideAllDivs() function needs to be the value of navRoot.parentNode.id at the time of this assignment (navRoot is initialized before this code), but instead the event is being created with the navRoot.parentNode.id value un-resolved and it is being resolved at runtime when the anchors are clicked on.  Unfortunately it is then the wrong value and I get errors that I spent a very long time tracking down to this cause.
 
There has got to be a way to write this to say use the value of navRoot.parentNode.id right now, not wait until later to resolve the value?
 
TIA
 
--------------
Ian Skinner
Web Programmer
BloodSource
www.BloodSource.org
Sacramento, CA
 
"C code. C code run. Run code run. Please!"
- Cynthia Dunning

Confidentiality Notice:  This message including any
attachments is for the sole use of the intended
recipient(s) and may contain confidential and privileged
information. Any unauthorized review, use, disclosure or
distribution is prohibited. If you are not the
intended recipient, please contact the sender and
delete any copies of this message. 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20041001/803670cf/attachment.htm>


More information about the Javascript mailing list