tags:

views:

185

answers:

2

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?

+2  A: 
<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/

bradenkeith
+1  A: 

shoot just a selected="yes" did the trick didn't do the trick

alex
Then you're using XHTML and not HTML. You should have been more explicit about that in the tagging. By the way, two options with the **same** value is a smell. Fix it. Fix your accept rate as well.
BalusC
@balusC and pandiya, you are right
alex