Mohamed Omar
Mohamed Omar

Reputation: 473

How to remove the empty options in a select box?

i have a select box which is really simple but it keeps outputting empty options which i don't have these options. why is this?

<form id ="orderby" action="" method="post">
    <select name="orderby"style="float:right;">
        <option selected="true" style="display:none;">choose view order</option>
        <option value="ASC" >Ascending<option>
        <option value="DESC">Descending<option>
    </select> 
    <input type="submit" value="Arrange" />
</form>

Upvotes: 0

Views: 36

Answers (2)

Kristijan Iliev
Kristijan Iliev

Reputation: 4987

There's no empty options. Your problem is because of not closing properly second and third option tags. Try this:

<form id ="orderby" action="" method="post">
   <select name="orderby"style="float:right;">
     <option selected="true" style="display:none;">choose view order</option>
     <option value="ASC" >Ascending</option>
     <option value="DESC">Descending</option>
   </select> 
   <input type="submit" value="Arrange" />
</form>

Upvotes: 1

Niki van Stein
Niki van Stein

Reputation: 10724

Because your selected option is set to display:none, either remove that or set one of the other options to selected.

Small detail you should use selected="selected" instead of true.

Upvotes: 0

Related Questions