HighDots Forums  

Changing HTML input text style color from javascript

Javascript JavaScript language (comp.lang.javascript)


Discuss Changing HTML input text style color from javascript in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Perdit
 
Posts: n/a

Default Changing HTML input text style color from javascript - 09-21-2003 , 05:55 PM






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

Reply With Quote
  #2  
Old   
Evertjan.
 
Posts: n/a

Default Re: Changing HTML input text style color from javascript - 09-21-2003 , 06:06 PM






Perdit wrote on 21 sep 2003 in comp.lang.javascript:

Quote:
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)


Reply With Quote
  #3  
Old   
Tom
 
Posts: n/a

Default Re: Changing HTML input text style color from javascript - 09-21-2003 , 07:21 PM



"Evertjan." <exjxw.hannivoort (AT) interxnl (DOT) net> wrote

Quote:
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




Reply With Quote
  #4  
Old   
Richard Cornford
 
Posts: n/a

Default Re: Changing HTML input text style color from javascript - 09-21-2003 , 08:00 PM



"Perdit" <cftranslate (AT) hotpop (DOT) com> wrote

Quote:
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.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.