If you change a dropdown and refresh the page, Firefox seems to ignore the selected attribute.
In firefox, I've notice that the "selected" attribute will not work unless you place the select inside a form, where the form has a name attribute.
With the name is better
form id="UMForm" name="UMForm" class="form"
The select will take the selected attribute
You could call .reset()
on the form before refreshing the page.
This is my solution:
var select = document.getElementById('my_select');
for(var i=0; i < select.options.length; i++){
select.options[i].selected = select.options[i].attributes.selected != undefined;
}
I just put that at the top of the page (with appropriate id set), and it works for me. Replacing the getElementById with a loop over all selects on the page, I leave as an exercise for the reader ;).
Add autocomplete="off"
HTML attribute to every select tag.
(source: https://stackoverflow.com/a/8258154/260080)
I'm using FF 25.0.1
It ignore selected=""
and selected="selected"
.
But if I simply try selected
the option is selected.
Strange (non conformant) behaviour. I know selected
is valid HTML5 and it's the shortest form, but I usually write code that also validates as wellformed XML, so that I can use any XML validation tool to check my results in a very strict way (and data exchange is very easy...)
According to W3C, these variants should be valid on boolean attributes:
HTML5: boolAttr="" | boolAttr="boolAttr" | boolAttr
XHTML5: boolAttr="" | boolAttr="boolAttr"
I prefer the first one, as is it nearly as short as the last (not xml conformant) variant but should validate as both XHTML5 AND HTML5. So I hope, Mozilla will fix it!