Reputation: 30097
How to set default selected element in combobox? Neither of the following worked for me:
Version 3:
<select id="parent">
<option value='null'>(Root)</option>
<option selected='yes' value='/'>Main</option>
</select>
Version 2:
<select id="parent">
<option value='null'>(Root)</option>
<option selected='true' value='/'>Main</option>
</select>
Version 1:
<select id="parent">
<option value='null'>(Root)</option>
<option selected value='/'>Main</option>
</select>
In all cases first option is selected on page, not that one which is marked selected.
SOME OTHER DETAILS
(1)
Page source beginning follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
...
(2)
Browser is Firefox 13.0.1
Upvotes: 12
Views: 67789
Reputation: 13925
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>
Upvotes: 5
Reputation: 775
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
Upvotes: 19
Reputation: 5483
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.
Upvotes: 38