Connecting Tech Pros Worldwide Forums | Help | Site Map

create and change the color of the option

mike
Guest
 
Posts: n/a
#1: Jul 25 '05
I am trying to change the style for an option in a select after it gets
created.

here is my code for creating the option:

function addOption(theSel, theText, theValue)
{
var newOpt = new Option(theText, theValue);
var selLength = theSel.length;
theSel.options[selLength] = newOpt;
theSel.options[selLength].style = "color:#ff0000";
}

I get an error on the style line.

Anyone know how I can change the color of the option?

Mike


Jedi Fans
Guest
 
Posts: n/a
#2: Jul 25 '05

re: create and change the color of the option


mike wrote:[color=blue]
> I am trying to change the style for an option in a select after it gets
> created.
>
> here is my code for creating the option:
>
> function addOption(theSel, theText, theValue)
> {
> var newOpt = new Option(theText, theValue);
> var selLength = theSel.length;
> theSel.options[selLength] = newOpt;
> theSel.options[selLength].style = "color:#ff0000";
> }
>
> I get an error on the style line.
>
> Anyone know how I can change the color of the option?
>
> Mike
>[/color]
not sure if all browsers allow option elements to be coloured but at any
rate:

theSel.options[selLength].style = "color:#ff0000";
should be:
theSel.options[selLength].style.color='#ff0000';
mike
Guest
 
Posts: n/a
#3: Jul 25 '05

re: create and change the color of the option


thanks, that works ... this particular page is an IE only page, so it
works fine.

Mike

Closed Thread