NationStates Jolt Archive


HTML(or Javascript):: Dropdown Menu Colors

Sel Appa
27-01-2007, 00:45
In this particular dropdown menu, how can you cange the color of each of the options? Is that even possible?


<form>
<select onChange="if(this.options[this.selectedIndex].value) top.location.href=(this.options

[this.selectedIndex].value)">
<option>Select an option</option>
<option value="">Option 1</option>
<option value="">Option 2</option>
<option value="">Option 3</option>
</select>
</form>


And is it Javascript or HTML?

Thanks :) I tried learning HTML and it's so pointless now. I don't really need a website and the market for those in the know is gone because of 50 million other people who know much more than me.
Iztatepopotla
27-01-2007, 02:26
Do you want each option to have a different color, or do you want colors to change somehow?

You can do the color bit with CSS, and if you want to change it depending on what option the user picks, then add some Javascript. That combination is called Dynamic HTML or DHTML for short.

Google that and go to the W3 Schools site www.w3schools.com for more info.
Sel Appa
27-01-2007, 03:35
Each option has a different backgorund color like red, orange, yellow...
Iztatepopotla
27-01-2007, 04:48
Each option has a different backgorund color like red, orange, yellow...

Okay. Make a new file called styles.css and enter:

option.orange {
background-color: orange;
}

option.red {
background-color: red;
}

option.yellow {
background-color: yellow;
}

then in the header of your html document:

<link rel="stylesheet" type="text/css" href="styles.css" />

and finally in the body:

<option class="orange" value="">Option Orange</option>
<option class="red" value="">Option Red</option>
<option class="yellow" value="">Option Yellow</option>

There are many other things you can do with CSS alone before even getting into Javascript and DHTML.