Html select option selected does not work

I'm just going to throw this out there because it has driven me crazy on more than one occasion:

When you refresh (F5) a page, Firefox preserves the selected values of any <select> elements on the page.

So if you're like me and write the select menu, load the page to make sure it works, then add the "selected" attribute, and refresh the page to make sure the selected one appears ... it won't (in Firefox, anyway).

Reloading the page entirely by clicking in the Address field and pressing Enter does honor the "selected" attribute.


Add selected to the option you want to be selected by default. Check the following example taken from here.

<!-- The second value will be selected initially -->
<select name="choice">
  <option value="first">First Value</option>
  <option value="second" selected>Second Value</option>
  <option value="third">Third Value</option>
</select>

Maybe the autocomplete form attribute is throwing you out.

Try adding autocomplete="off" to the form tag.

This way even when you refresh the page in FF the selected attribute is respected.

GL

Tags:

Html

Combobox