0

I have looked around for a while now and could not find anything. The thing I want to do is to have a dropdown menu and have a default title on it, but when you press the option it will change it to that (which it already does). I have this basic code here:

    <select>
        <option>Choose Color</option>
        <option value="red">Option 1</option>
        <option value="green">Option 2</option>
        <option value="blue">Option 3</option>
    </select>

So here I have 4 options. However I only want 3 (because at the moment "Choose Color" is an option which I do not want) and I want the "Choose Color" just to be a title for if nothing is selected (or default). - Thanks

Bitten Fleax
  • 262
  • 4
  • 20
  • You can use [`optgroup`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/optgroup) – Martin Smith Nov 09 '14 at 17:02
  • possible duplicate of [How to add a title to a html select tag](http://stackoverflow.com/questions/18179960/how-to-add-a-title-to-a-html-select-tag) – Martin Smith Nov 09 '14 at 17:02

2 Answers2

1

You could use this trick:

<select>
    <option selected="selected" disabled="disabled" value="" style="display: none;">Select your option</option>
    <option value="red">Option 1</option>
    <option value="green">Option 2</option>
    <option value="blue">Option 3</option>
</select>

Improved answer from here.

Community
  • 1
  • 1
skobaljic
  • 9,379
  • 1
  • 25
  • 51
0

You can try this:

<select>
    <option style="display: none;">Choose Color</option>
    <option value="red">Option 1</option>
    <option value="green">Option 2</option>
    <option value="blue">Option 3</option>
</select>
Weafs.py
  • 22,731
  • 9
  • 56
  • 78