[thelist] Problem accessing for values with []

Christian Heilmann lists at onlinetools.org
Thu Feb 10 17:42:08 CST 2005

Jonathan Dillon wrote:

>Howdy all:
>Thanks for the help with the cert. ;-)
>I'm on to my second odd problem!  I've got a javascript file that needs to
>make reference to the following form:
>alert('val: ' + document.main.form[journal].value);
document.forms.main.journal.value should work. No idea where you  found 
the  above syntax. [] always indicates an array, hence you'd need 
forms[1] or forms['foo'] there, unless journal is a variable.
document.forms['main'].elements['journal'].value is the cleaner version, 
or if  you use name and  ID anyway, document.getElementById('journal')

More information about the thelist mailing list