[thelist] javascript variable in DOM selector

Matt Warden mwarden at gmail.com
Mon Jun 16 22:51:06 CDT 2008


On Mon, Jun 16, 2008 at 11:27 PM, Aaron Vegh <aaronvegh at gmail.com> wrote:
> 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?

Syntax issue. The way you have it written, it is looking for a
property named sourceName on the form object. Try
...forms[0].elements[sourceName].style...

-- 
Matt Warden
Cincinnati, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the thelist mailing list