954,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

default "selected" option in firefox not working

Hey, I'm trying to use a simple select menu, and I would like to set one of the values to be the default, and it works great in IE, but not in firefox. Here is a sample:

<select name="test">
<option value="Test 1">Test 1</option>
<option value="Test 2">Test 2</option>
<option value="Test 3" selected>Test 3</option>
</select>


Notice that I am trying to get "Test 3" to show up as the default option. It works fine in IE, but how do I get it to work in Firefox too?

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

are you using an HTML or XHTML doctype?

in HTML doctypes it's ok to set boolean attributes without values, in XHTML doctypes it is not.

in XHTML you have got to use:

selected="selected", or selected="yes", or selected="true"

MattEvans
Veteran Poster
Moderator
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
 
are you using an HTML or XHTML doctype? in HTML doctypes it's ok to set boolean attributes without values, in XHTML doctypes it is not. in XHTML you have got to use: selected="selected", or selected="yes", or selected="true"

Lol, well, I don't know enough to stay XHTML valid, but if I know it I will, so thanks for the info.

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

does it work in Firefox if you use one of those atttribute values instead of just 'selected'?

it's not so much a question of staying valid, as being compatible.

an absolutely 'correct' XML parser should reject that line of code and output a warning/error message instead of an expected output. But, Firefox only ever truely parses a page as X(HT)ML if you serve the Content-Type:application/xhtml+xml* header.

* not sure if that's the correct type, it's not an easy one to remember.

MattEvans
Veteran Poster
Moderator
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
 
does it work in Firefox if you use one of those atttribute values instead of just 'selected'? it's not so much a question of staying valid, as being compatible. an absolutely 'correct' XML parser should reject that line of code and output a warning/error message instead of an expected output. But, Firefox only ever truely parses a page as X(HT)ML if you serve the Content-Type:application/xhtml+xml* header. * not sure if that's the correct type, it's not an easy one to remember.

Well, to be honest, after I read your reply, I went back to go change it, and I decided to look at the page one more time, and it was working! I have no idea why. So I didn't change it. Maybe I'll change it just to please our curiosity now...

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

Ok, I just tried it again. And I realized when I said it was working before, it was because I was simply refreshing the page, but apparently Firefox retains all the information, so it didn't matter what had "selected" in the script, it was just selecting the one that was previously selected.

So I closed the window, opened a new one, and realized it wasn't working with just "selected" in the script. When i changed it to selected="yes", it worked.
Thanks.

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

Thanks a lot, would have spent hours trying to get it working if it wasn't for this thread.

The outcome: Firefox retains the last value you had a form field at when hitting refresh so to debug/test add "?1" or something similar to the URL to restart from afresh. Ctrl+Refresh doens't even work.

Next of all, 'SELECTED="yes"' worked in the end for me.

Thanks again!

kevindougans
Junior Poster
129 posts since Oct 2007
Reputation Points: 13
Solved Threads: 7
 

From what I know, Shift-Refresh will force most Mozilla browsers to grab a new copy of a page from the server rather than cache.

trudge
Junior Poster
178 posts since Sep 2007
Reputation Points: 18
Solved Threads: 20
 

yes you are correct, i edited content on the page and the content change but for whatever reason it doesn't refresh the form fields from the options you had last selected. i guess some would find this feature cool so they don't have to keep refilling forms out.

kevindougans
Junior Poster
129 posts since Oct 2007
Reputation Points: 13
Solved Threads: 7
 

Whether or not to clear fields is a setting.

MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
 

Ok, I just tried it again. And I realized when I said it was working before, it was because I was simply refreshing the page, but apparently Firefox retains all the information, so it didn't matter what had "selected" in the script, it was just selecting the one that was previously selected.

So I closed the window, opened a new one, and realized it wasn't working with just "selected" in the script. When i changed it to selected="yes", it worked. Thanks.

do it like this: selected=true blsa sldfsmdkask>
this will work, in ff2.0 and ie7 (thats what i have)

emsee
Newbie Poster
1 post since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

I have the same problem of firefox remembering the previous setting. And yes, I see where that is able to be disabled in the firefox options.

selected="yes" is not valid xhtml, should be selected="selected"

The autocomplete="off" does not even work :(

I am using the autocomplete in the to try and disable for a drop down menu.

Any other ideas?

T2DMan
Newbie Poster
2 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

The quotes must be there in XHTML. It must be in the selected="selected" form, not the selected=selected form.

MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
 

Found out that there was some javascript being used to override the settings. Bugfixing someone elses code, sometimes things are a little hidden.

Now working perfectly.

T2DMan
Newbie Poster
2 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 
do it like this: selected=true blsa sldfsmdkask> this will work, in ff2.0 and ie7 (thats what i have)

You need to make sure that "Firefox Preferences -> Privacy -> remember search and form history" is unchecked.

I know this post is very old, BUT people do google for things like this, so it's good if there's a solution even if it's years later for the actual people. I wish some people on forums would understand this obvious fact!!!!!! Instead of moaning about lates posts!

xandrani
Newbie Poster
2 posts since Apr 2010
Reputation Points: 14
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You