PDA

View Full Version : Dynamically setting color


kipsta
11-06-2004, 09:00 AM
I have a test field in a view that I want to dynamically change the color of depending upon the data. The field is defined with fgcolor="green", what I want to do is change it to red depending upon the data. Unfortunately, if I execute a setAttribute on it for the fgcolor, it turns the test to black, no matter what I do.

What I have in the code is below:

selectedView.offsetText.setAttribute('fgcolor', 'red');

if I remove this line, the text stays green as previously defined, but with this, it turns black.

Any ideas?

mcgaffin
11-08-2004, 07:07 AM
I've run across this, too. All you need to do is change your code to:


selectedView.offsetText.setAttribute('fgcolor', red);


Notice there are no quotes around the color. Because you are setting an attribute of type "color", you do not need quotes. Also, if you want to set a color with a hex number, you would do it like so:


myview.setAttribute('fgcolor', 0xdee1f5);


not


myview.setAttribute('fgcolor', "#dee1f5");


- david

kipsta
11-08-2004, 03:11 PM
Thanks :)