473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

HTML Select option selected color style

Is there a style for a select option's "selected" color? For example:

<HTML>
<BODY>
<FORM NAME="form1">
<SELECT NAME="mySelect" SIZE="7" style="background-color:red;">
<OPTION>Test 1
<OPTION>Test 2
<OPTION>Test 3
<OPTION>Test 4
<OPTION>Test 5
<OPTION>Test 6
<OPTION>Test 7
</SELECT>
</FORM>
</BODY>
</HTML>

When I select an option it turns blue, I want to override this and
make it a different color. In the style I expected something like
"selected-color", but it doesn't exist. I've also tried using
javascript to change the background color (works if I click on a
different option using the onClick event
mySelect.option[2].style.backgroundColor="green"), but something seems
to be overriding it if I click on the option I want to change). Here's
the code for that option that I've been playing with:

<HTML>
<HEAD>
<TITLE>

</TITLE>
<SCRIPT>
function init() {
document.formName.selectName.options[5].style.backgroundColor
='green';
document.formName.selectName.options[5].style.color ='red';
document.formName.selectName.options[5].style.foregroundColor
='orange';
document.formName.selectName.options[5].style.bgColor ='red';
}
function test(tst) {
alert(tst);
document.formName.selectName.options[5].style.backgroundColor
='black';
document.formName.selectName.options[5].style.color ='black';
document.formName.selectName.options[5].style.foregroundColor
='black';
document.formName.selectName.options[5].style.bgColor ='black';
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="init();">
<FORM NAME="formName">
<SELECT NAME="selectName" style="background-color:red" SIZE="7"
onclick="window.event.cancelBubble='true';test('on click')">
<OPTION>TEST 1
<OPTION>TEST 2
<OPTION>TEST 3
<OPTION>TEST 4
<OPTION>TEST 5
<OPTION>TEST 6
<OPTION>TEST 7
</SELECT>
</FORM>
</BODY>
</HTML>

Any ideas appreciated!

Thanks!
Jeff
Jul 20 '05 #1
4 102909
jc********@statestreetkc.com (Jeff Anderson) wrote:
Is there a style for a select option's "selected" color?


You could try option:focus {} but I doubt you'd have much luck and it
certainly wouldn't work in IE.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #2
Steve Pugh <st***@pugh.net> wrote:
jc********@statestreetkc.com (Jeff Anderson) wrote:
Is there a style for a select option's "selected" color?


You could try option:focus {} but I doubt you'd have much luck and it
certainly wouldn't work in IE.


I should have added that CSS3 has the :checked pseudo-class will be
the proper way of doing this. At least I think so, it may or may not
apply here (the examples given are of radio buttons and checkboxes;
but the mention of the HTML selected attribute can be taken as
including option elements, as they're the only element that attribute
exists for).

However, I know of no browser that supports this part of CSS3 yet.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #3
Steve Pugh <st***@pugh.net> wrote:
Is there a style for a select option's "selected" color?


You could try option:focus {} but I doubt you'd have much luck and it
certainly wouldn't work in IE.


The :focus pseudo-class is confusingly defined in the specification and
inconsistently implemented in vrowsers. But I think it is certainly not
meant to be identical with the concept of 'selected option' when used
for an option element. When you have selected an option from a
select menu and then move to another field, by tabbing or clicking for
example, then surely the focus moves away from the select or option
element, if it was there.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jul 20 '05 #4
Steve Pugh wrote:
However, I know of no browser that supports this part of CSS3 yet.


Mozilla: <http://bugzilla.mozilla.org/show_bug.cgi?id=120834>
--
Anne van Kesteren
<http://www.annevankesteren.nl/>
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bruce | last post by:
For those of you using templates to keep your PHP and HTML code separate..... How do you handle a HTML Select statement when the initial option selected needs to come from a database field? ...
2
by: Targa | last post by:
I have a select box with about 5 options. I need to have one of the options, when selected, display a second select box. The second select box is populated by a database and needs to be preloaded...
3
by: Oeivind | last post by:
Hi at all ! When I select an option or the SELECT item gets focus, it turns blue, I want to override this and make it a different color. Is there some cure for this ? Oivind
3
by: ANTISPAM_garycnew_ANTISPAM | last post by:
What is the simplest way to retain the last option value selected in an html select object using javascript? I am currently using a server-side cgi language to accomplish this task, but it adds...
6
by: artev | last post by:
if I have a select with more options, how I can know if is there an option selected; is necessary a cycle? or is there an inner property?
1
by: empiresolutions | last post by:
I have a page where the <select> is very screen right. it has little room to show the full name in the <option> so i do like "S - Summary". You only end up seen the S. When the dropdown happens, my...
2
by: Problematic coder | last post by:
I have a need in an application to have the ability to select multiple values in some kind of drop down list or maybe even a html type select box. I have found there doesn't seem to be an option...
7
by: fsalvador | last post by:
Hi, I am trying to figure it out how to to hide in onmouseout the select options of a form. Below is the code I got so far. It isn't working. Please help. Thanks <!DOCTYPE HTML PUBLIC...
2
by: saurabh moses | last post by:
hi can anybody help me on <select> option in website I have multiple option bar with multiple choices i want when i select one choice in one bar it show only related choices on another option bar....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.