Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select first empty value option in a select menu?

The following always preselects the last option, even when I set the selected attribute, but I like the first option to be preselected.

<select name="filter">
    <option value="" selected>Make a choice</option>
    <option value="1">1</option>
    <option value="3">3</option>
    <option value="7">7</option>
    <option value="">all</option>
</select>

Can this be done?

like image 384
alex Avatar asked Dec 12 '22 22:12

alex


1 Answers

<select name="filter">
    <option value="" selected="selected">Make a choice</option>
    <option value="1">1</option>
    <option value="3">3</option>
    <option value="7">7</option>
    <option value="">all</option>
</select>

If my code modification does not work. Check this article and make sure it's not something you're running in to http://www.beyondcoding.com/2008/12/16/option-selectedselected-not-working/

like image 181
bradenkeith Avatar answered Jan 12 '23 05:01

bradenkeith