[thelist] javascript variable in DOM selector

Aaron Vegh aaronvegh at gmail.com
Mon Jun 16 22:27:13 CDT 2008


Hi there,
I'm struggling with a bit of javascript. Hoping this is an obvious
issue that I'm overlooking. This code works fine:

document.forms[0].sourceName1.style.display="inline";

When activated with the function it resides in, this line correctly
changes the element in question. But this code:

var sourceName = "sourceName1";
document.forms[0].sourceName.style.display="inline";

does not work. Firebug tells me that sourceName (in the second line)
is undefined. So can you put variables in DOM selectors, or what?

Thanks!
Aaron.

-- 
Aaron Vegh, Principal
Innoveghtive Inc.
P: (647) 477-2690
C: (905) 924-1220
www.innoveghtive.com
www.website-in-a-day.com



More information about the thelist mailing list