Soledad M

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromSoledad M
ToMe
SubjectSafari style problem
Date10 August 2005 17:18
Hi,
my name is Stef and i am abeginner ASP developer.
i need your help about this problem:
i have this fragment
<select name="mySelect">
   <option value="1">one</option>
   <option value="2">two</option>
</select>

I want the text of these optios to be in some coler, for example
red(#ff0000), so i've added in each option this: class=redType, where in css
file i have defined the redType class as:
  .redType {
    color:#FF0000
   }
This works in IE, but not in Safari.

Also later i want to add new option in the "mySelect" select list, so i do
some kind of this code in javascript function:

  var newOption = new Option(sWord, sValue);
  newOption.style.color = "#00FF00";
  if (document.all)
       objCombo.options.add (newOption);
  else
        mySelect.options[objCombo.options.length] = newOption;

So Again the new option using IE is added and colored, and those with Safari
is just added but not colored in "#00FF00".

Would you please tell me where i my mistake. Friend of mine told me that
there is a possibility that Safari doesnt support color for options items.

Thank you,
Stef
FromMe
ToSoledad M
SubjectRe: Safari style problem
Date10 August 2005 19:59
Stef,

> Would you please tell me where i my mistake. Friend of mine told me that
> there is a possibility that Safari doesnt support color for options items.

It is not your mistake. Safari cannot colour 'select' or 'option' elements.
This is because it uses the Mac OS X select widget, which itself is not
capable of being styled. The same applies to other browsers that use this
widget, such as iCab or OmniWeb.

Other Mac browsers like Opera or Firefox allow the select input to be
styled, but may not be able to style individual option elements.

As a side note, this is not a good idea:

if (document.all)
  objCombo.options.add (newOption);

What you are doing has nothing to do with document.all (and don't forget
that IE is not the only browser to support document.all - Opera, Konqueror,
iCab, IE Mac [which does not work with what you are trying to do] all
support it as well). Do not detect one thing then assume another thing.

In this particular case, what you are doing is not needed anyway. All
browsers understand the non-IE version (including IE) so just use that:

  var newOption = new Option(sWord, sValue);
  newOption.style.color = "#00FF00";
  mySelect.options[mySelect.options.length] = newOption;


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.