Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set an un-selectable default description in a select (drop-down) menu in HTML?

I have a drop down where the user selects a language:

<select>     <option>English</option>     <option>Spanish</option> </select> 
  1. I want the default option that is initially displayed to say "Select a language" instead of "English" (my first option, displayed by default).
  2. I don't want the user to be able to select "Select a language".
like image 412
RSM Avatar asked Mar 06 '11 19:03

RSM


People also ask

How do you make a dropdown Unselectable in HTML?

disabled="" , disabled="false" , and just disabled all have the same effect.

What attribute is used in drop down menu to indicate a default selected option?

Definition and Usage. The selected attribute is a boolean attribute. When present, it specifies that an option should be pre-selected when the page loads. The pre-selected option will be displayed first in the drop-down list.

How do I select multiple options from a drop-down list in HTML?

To select multiple items, the user has to hold down the shift or ctrl key, then select with the mouse.


1 Answers

Building on Oded's answer, you could also set the default option but not make it a selectable option if it's just dummy text. For example you could do:

<option selected="selected" disabled="disabled">Select a language</option> 

This would show "Select a language" before the user clicks the select box but the user wouldn't be able to select it because of the disabled attribute.

like image 99
Glen Selle Avatar answered Sep 27 '22 21:09

Glen Selle