Jump to content

<select> colour different from the default


freelance84

Recommended Posts

($ii > 7)
{
	echo "<option style=\"color:red;\">none choosen</option>";
}

 

The above bit of code works perfectly; If $ii is greater than 7 the text color on that option is changed to red with a bit of CSS.

 

The problem is, the said option is only red in the drop down list. When the user selects the option it reverts back to the default color, black.

 

Is it possible to keep the option in red even after it has been choosen?

 

Its no big deal either way, it's just it would look miles better if it could.

 

Any pointers or advice would be very much appreciated.

 

(I have a sneaky feeling it may not be CSS which will control this and it may be the dreaded js)

Link to comment
Share on other sites

touch'e

 

 

The output would be:

<select name="name">
  <option>oak</option>
  <option>maple</option>
  <option style="color:red;">none choosen</option>
</select>

 

Ok then, above is the output of the html. The drop down list has three options and the "none choosen" is styled red with CSS.

 

When the said option is selected (ie when the drop down menu closes back up) its colour changes to the default, black.

 

My question is, is it possible to keep its colour being red even after it has been selected?

Link to comment
Share on other sites

I read something about this the other day. It seems that when the combobox closes, the style of the SELECT element takes control rather than the style of the selected OPTION.  At least, this happens in some browsers. The suggested solution was to use some javascript for the onClick attribute (I think) that would copy the style from the selected OPTION to the style of the SELECT element.  I came across this when I was googling for a combobox color selector (or something like that).

Link to comment
Share on other sites

Yea i had a sneaky idea that it might be done with js

 

Thanks for trying though.

 

For the moment I will just hvae to stick with red in the drop down menu and black when selected.

 

When I've completely finished the site with css html php and mysql, I will then start looking at implementing js for additional benifits.

 

Thanks again  :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.