Firefox not preselecting selects

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Firefox not preselecting selects

Post by matthijs »

Did you know that Firefox does not preselect options in a select form element?

Code: Select all

 
        <select name="training_intensity" id="training_intensity" >
            <option  value="5" >Very hard</option>
            <option value="4" >Hard</option>
            <option  value="3" >Normal</option>
            <option value="2" >Easy</option>
            <option  selected="selected" value="1" >Recovery</option>
        </select>   
 
In any other browser the option Recovery is preselected. Not in Firefox 3 on Mac ....

(maybe I'm light years behind discovering this. But it was a real "WTF?" moment when I couldn't figure out why my code didn't work)
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Firefox not preselecting selects

Post by Eran »

That's very weird. It works in FF3 on windows
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Re: Firefox not preselecting selects

Post by matthijs »

Wait. I discovered it has to do with Firefox's caching/remembering of form values. A soft refresh (ctrl-r) will still retain the previous preselect, even if I disable cache in the web dev toolbar.

Hitting shft-ctrl-r (a hard refresh) does preselects the right value.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: Firefox not preselecting selects

Post by Bill H »

Have you tried it with

Code: Select all

<option  value="1"  selected>Recovery</option>
 
Or, simply make it the first option in the list, which I believe is displayed if none if the following options is tagged as selected.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Firefox not preselecting selects

Post by JAB Creations »

Bill H wrote:Have you tried it with

Code: Select all

<option  value="1"  selected>Recovery</option>
 
That's invalid (X)HTML, an attribute can not simply exist by itself.

I've only run an x86 OS X on a second AMD system about a year ago to test OS X versions of browsers and in general the bugs all seemed cross-platform related.

If you reload a page it will select the option you had selected. If you GO to the page it'll select the default value. To go to the page you'll need to fix the go button of which I have posted a solution without the need for an extension for such a critical GUI component...
http://www.jabcreations.com/blog/firefo ... -go-button
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: Firefox not preselecting selects

Post by Bill H »

That's invalid (X)HTML, an attribute can not simply exist by itself.
I was merely suggesting that he try it to see what happened. I'm not a criminal that would actually do something like that.
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Re: Firefox not preselecting selects

Post by matthijs »

As I posted it is an issue of the pre-filling of forms in Firefox and a hard refresh solves the issue. When posting a form and reshowing the problem doesn't exist. So for now the issue is solved. It was just a very weird moment when doing soft refreshes didn't do what I expected. Ctrl-r is such a wired shortcut, I hit it before even thinking about it. (which does cause problems in the rare cases I open up Windows, I keep hitting inappropriate shortcuts..)

And of course it's too bad this is another issue that differs between browsers (please, get together and work on those standards!)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Firefox not preselecting selects

Post by josh »

FF has a "feature" that sometimes if you've been working with a form and use the back button to return to it, the last _user_ selected option will remain active, even upon page refresh. If you close the tab and re-key the URL directly it should revert to the programmer preselected option ( or if you use firebug you can click the element and look at your markup to see which element would have been selected )
Post Reply