473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Changing HTML input text style color from 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'

Thanks
Jul 20 '05 #1
3 43280
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: multimatum2 | last post by:
Hello, I need to enable/disable input text forms... But... I need to have the same style (color...) in both modes.. Could you help me ? Thanx a lot A small sample... ...
4
by: frogman042 | last post by:
My daughter is playing around trying to learn JavaScript and she wrote a small program that prints out a message in increasing and decreasing font size and color changes. She is using document...
3
by: addi | last post by:
I'm looking to perform input validation on an HTML input text element; specifically, I'm looking to prevent anything other than numerical characters from being entered. I've got it working just...
3
by: Ali | last post by:
I have 3 html input tex in my asp.net form. Two of them are calling javascript client side to calculate the differnce of two dates and put the result into the third input text. i haven't include...
3
by: jd | last post by:
I want to be able to detect all changes to an html input text field. I can catch keyboard events but I can't figure out what event gets triggered if the text was inserted in some other way -- for...
2
by: magix | last post by:
Hi, I'm using Access Database with ASP. There is one particular thing that I have issue with. My purpose is for user to update their own profile. Their existing profile information will be...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
5
by: Shisou | last post by:
I'm trying to put together a form and so far it's been all ASP coding, now i wanna make it a bit more dynamic, but i'm kinda new to Javascript. so i hope you guys can help me. What i have now is a...
3
by: coolnags | last post by:
Hi, I have created 2 html input text boxes with readonly property set to 'readonly'. I am handling the esc key event(27) in javascript code. When I press the esc key for the first time it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.