473,321 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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

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
Jul 23 '05 #1
1 1078
Lee
Ian Skinner said:

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]
I find it much more readable as:

node.childNodes[0].onclick=function() {
showHideAllDivs( navRoot.parentNode.id,
this.innerHTML.replace(/[^A-Za-z]/g,""),
this.id
);
return false;
}

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?


Instead of:
onclick=function(){...}
use:
onclick=new Function("showHideAllDivs("
+navRoot.parentNode.id+","
+"this.innerHTML.replace(/[^A-Za-z]/g,''),"
+"this.id);return false;");

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
2
by: Martin | last post by:
Hallo, can you help me writing a generic xslt transformation (useable with xsql from oracle)? The problem is how to get the escaping characters .... === INPUT-File in.xml <?xml version =...
2
by: Thomas Matthews | last post by:
Hi, I'm getting linking errors when I declare a variable in the global scope, but not inside a function. The declarations are the same (only the names have been changed...). class Book {...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
3
by: Dennis Chang | last post by:
Hi all, I was reading about function pointers and came across something which intrigued me. K&R2 calls qsort (pg.119) within main as so: qsort( (void **) lineptr, 0, nlines-1, (int (*) (void...
4
by: louise raisbeck | last post by:
Hi there, I have created a vb server function which i want to evaluate when a server control button is clicked (only!) however it is evaluating the code on load even though i havent put it into the...
14
by: Laser Lu | last post by:
Hello, All, I just want to know that generally how to get the HtmlForm element in an ASP.NET Page? Can anybody help? Please:) Best regards, Laser Lu
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
8
by: vaib | last post by:
hi all , It really seems that C never ceases to amaze . All this time i've been doing C and i thought i was quite adept at it but i was wrong . So without wasting any more time , here's the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.