View Full Version : "selected" attribute problems in <option>

06-02-2005, 04:32 AM
I've tried in IE and Firefox and this attribute works in neither one for <option> tags. According to the W3C (http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.6.1) you can assign a "selected" attribute to options in a <select> dropdown in order to force a certain value to be pre-selected when the page loads. But what happens is that the browser will show the selected value for the first time, but then when you refresh, it will be at the value that you left it at rather than the selected option in the dropdown (for example, if you refresh the page, it will at the value you left it at rather than what you used.

<form action="">
<option value="0">Default</option>
<option value="1" selected="selected">Selected option</option>

I have found that resetting the form on page load works, although it's not visually appealing. But for sake of javascript, rather than depending on a preset option matching a pre-selected value, it's better to get the value of the selected option (regardless of how it became selected, whether it be pre-selected or from the browser cache bug), and use it as a function argument. Was this problem intentional or unexpected?

06-02-2005, 06:44 PM
Works in Safari ;)

Does it matter if you make it a list instead of a menu? i.e.
<select size="1">