469,610 Members | 1,554 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

Problems with .bgColor



I am trying to change a group of background colors by calculating their
names in a loop . Names are cfh13, cfh15, cfh17, etc...

Unlooped code like

cfh17.bgColor="#CCFFFF" ;

works just fine.

Code that does NOT involve a background color change but is calculated
within a loop works just fine, such as...

form[curedg + "s"]["value"] = "zorch" ;

But this does not....

form["cfh" + 17]["bg.Color"] = "#CCFFFF" ;

What am I doing wrong and how can I loop changing a named group of
background colors?
--
Many thanks,

Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: do*@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com
May 20 '07 #1
5 1702
Lee
Don Lancaster said:
>
I am trying to change a group of background colors by calculating their
names in a loop . Names are cfh13, cfh15, cfh17, etc...

Unlooped code like

cfh17.bgColor="#CCFFFF" ;

works just fine.

Code that does NOT involve a background color change but is calculated
within a loop works just fine, such as...

form[curedg + "s"]["value"] = "zorch" ;

But this does not....

form["cfh" + 17]["bg.Color"] = "#CCFFFF" ;

What am I doing wrong and how can I loop changing a named group of
background colors?
Your examples of what works and what doesn't should be more
similar, in order to help to determine where the problem lies.

There is no attribute named "bg.Color". If that was just a typo
in your post, and doesn't appear in your code, then you need to
learn to copy from your code and paste into your posts to avoid
wasting everybody's time.

Assuming that this also works:

form["cfh17"]["bgColor"] = "#CCFFFF" ;

then this should work:

form["cfh" + 17].bgColor = "#CCFFFF" ;

If the first case doesn't work, then the problem may be that
cfh17 isn't a form element, so you can't access it via the
form collection.
--

May 20 '07 #2
Lee wrote:
Don Lancaster said:
>>

I am trying to change a group of background colors by calculating their
names in a loop . Names are cfh13, cfh15, cfh17, etc...

Unlooped code like

cfh17.bgColor="#CCFFFF" ;

works just fine.

Code that does NOT involve a background color change but is calculated
within a loop works just fine, such as...

form[curedg + "s"]["value"] = "zorch" ;

But this does not....

form["cfh" + 17]["bg.Color"] = "#CCFFFF" ;

What am I doing wrong and how can I loop changing a named group of
background colors?


Your examples of what works and what doesn't should be more
similar, in order to help to determine where the problem lies.

There is no attribute named "bg.Color". If that was just a typo
in your post, and doesn't appear in your code, then you need to
learn to copy from your code and paste into your posts to avoid
wasting everybody's time.

Assuming that this also works:

form["cfh17"]["bgColor"] = "#CCFFFF" ;

then this should work:

form["cfh" + 17].bgColor = "#CCFFFF" ;

If the first case doesn't work, then the problem may be that
cfh17 isn't a form element, so you can't access it via the
form collection.


..bgColor is an attribute of a table cell and seems to work properly
except as noted above.

The greater problem is to change the background colors of certain table
cells by their input name with a loop, instead of one at a time.

Unlooped code appears as a small part of http://www.tinaja.com/demo28a.asp
--
Many thanks,

Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: do*@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com
May 20 '07 #3
Don Lancaster wrote on 20 mei 2007 in comp.lang.javascript:
.bgColor is an attribute of a table cell and seems to work properly
except as noted above.
I suggest you use style.background-color instead of .bgColor
The greater problem is to change the background colors of certain table
cells by their input name with a loop, instead of one at a time.

Table cells do not have an input name.

Is a loop not accessing one at a time?

Perhaps you want this:

var myCells = form["cfh" + 17].cells
for (var n=0;n<myCells.length;n++) {
if (myCells[n].name == 'blah')
myCells[n].style.background-color = "#CCFFFF";
}

not tested.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 20 '07 #4
Evertjan. said the following on 5/20/2007 1:39 PM:
Don Lancaster wrote on 20 mei 2007 in comp.lang.javascript:
>.bgColor is an attribute of a table cell and seems to work properly
except as noted above.

I suggest you use style.background-color instead of .bgColor
style.backgroundColor might work better :-)

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 20 '07 #5
Randy Webb wrote on 20 mei 2007 in comp.lang.javascript:
Evertjan. said the following on 5/20/2007 1:39 PM:
>Don Lancaster wrote on 20 mei 2007 in comp.lang.javascript:
>>.bgColor is an attribute of a table cell and seems to work properly
except as noted above.

I suggest you use style.background-color instead of .bgColor

style.backgroundColor might work better :-)
True, my mistake.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 20 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Michael Fork | last post: by
4 posts views Thread by Alex Meier | last post: by
34 posts views Thread by aljamala | last post: by
4 posts views Thread by ronboulder | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.