drake035
drake035

Reputation: 2897

How to create a <select> placeholder

In my select elements, I want a default text such as "please select an option". Also I use the jQuery plugin Validation with my form so that the user cannot submit the form if he has not selected something in my select elements.

Problem is, if I have "please select an option" in my selects, the form will validate.

How to deal with this problem?

Upvotes: 2

Views: 10952

Answers (2)

Larry Donne
Larry Donne

Reputation: 41

<select>
    <option style="display:none">please select an option</option>
    <option disabled="disabled">I am a line</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>

Upvotes: 4

Explosion Pills
Explosion Pills

Reputation: 191749

<select>
    <option value="">Please select an option</option>

<option> content is only used when the value is not empty.

http://jsfiddle.net/s5AVg/

Upvotes: 4

Related Questions