Problems with .bgColor

D

Don Lancaster

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: (e-mail address removed)

Please visit my GURU's LAIR web site at http://www.tinaja.com
 
L

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.


--
 
D

Don Lancaster

Lee said:
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: (e-mail address removed)

Please visit my GURU's LAIR web site at http://www.tinaja.com
 
E

Evertjan.

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.
 
E

Evertjan.

Randy Webb wrote on 20 mei 2007 in comp.lang.javascript:
Evertjan. said the following on 5/20/2007 1:39 PM:

style.backgroundColor might work better :)

True, my mistake.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top