By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,071 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

Changing HTML input text style color from javascript

P: n/a
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'

Thanks
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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'

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2

P: n/a
Tom
"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
Jul 20 '05 #3

P: n/a
"Perdit" <cf*********@hotpop.com> wrote in message
news:63**************************@posting.google.c om...
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'


The elements collection of a form is an object so JavaScript property
accessor syntax uses square brackets not parenthesises.

<URL: http://jibbering.com/faq/#FAQ4_39 >

The style property of an Element holds a reference to an object and
assigning a CSS 'color' property to that object involves setting its
color property:-

document.forms['myform'].elements['element-'+

counter].style.color = '#FF0000';

Richard.
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.