I’m almost out of hair on this. I have a select list which has a couple of colour coded items on it. The color is added via a style attribute as this is read from a database table that contains the agency details and ‘color code’. Here’s how that looks:
So agency 4 and agency 1 have a background color and the others don’t. That works fine - when you drop the list down you see the colors. My problem is getting the color into the background of the select list control after the option is selected. If the background on the option is green, then it should retain its green background when it becomes the selected item.
… it always tells me that the background-color is rgb(51,153,255). I believe that may be the blue color that a selected item has by default.
So, my main problem is that no matter what I try here (and I’ve been trying for the past couple of hours) I can’t get the background color from the style attributes on those two select items that have the different background-color.
Without looking into it too deeply, the only way I can do it atm is to click away from the <select> or to set focus to another element after I select one of the coloured options. This way the the options bg colour is retained after it is selected.
As a workaround I put an onchange in the <select> to set focus to another input element, which you hopefully have on the same page, in order to retain options’ 1 and 4 bg colour when they are selected.
Not all browsers are going to support making the background different colours in the first place. For example IE6 uses the select list functionality directly out of the operating system and so it ignores all attempts to style it at all and can’t have anything else in front of it.