[thelist] javascript variable in DOM selector

Anthony Baratta anthony at baratta.com
Mon Jun 16 23:07:05 CDT 2008

var sourceName = "sourceName1";

Aaron Vegh wrote:
> 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.

More information about the thelist mailing list