"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn*******************@194.109.133.29...
Perdit wrote on 21 sep 2003 in comp.lang.javascript:
I am wondering why this does not work in javascript. The html color is
set to automatic (none)
element1, element2, etc are input fields (textboxes)
document.myform.elements('element-'+counter).style='color: #FF0000'
document.myform(counter-1).style.color = '#FF0000'
Let 's try another one:
document.myform['element'+counter].style.color='#ff0000';
Important things to note:
- square brackets.
- no dot or anything between "myform" and the opening bracket.
- "myform" can be any string, as long as it is the same as
the "name='myform' " bit in the actual form opening tag.
- counter can be an integer 1, or a string "1", but not "01" or " 1" with a
space.
If you want to use a hyphen (-) like in your example line of code, the
element names should also be renamed to element-1, element-2, etc. I think
hyphens are legal in element names, but am not sure.
HTH
Tom