8

I'm rendering a drop down box that contains a currently selected value using selected="true".

<select id="dropDown"> 
    <option selected="true" value="1">value2</option>
    <option value="2">value3</option>
    <option value="3">value4</option>
</select>

Initially the selected value corresponds to the selected="true", but if I play around with the drop down box and then refresh the page the selected="true" is ignored and the displayed value is the last one I chose. I tried using selected="selected" with the same results. Thanks for your help.

Jaak Kütt
  • 2,566
  • 4
  • 31
  • 39
Assaf Karmon
  • 915
  • 1
  • 10
  • 23
  • Possible duplicate of http://stackoverflow.com/questions/2486474/preventing-firefox-from-remebering-the-input-value-on-refresh-with-meta-tag – j08691 Jan 09 '12 at 16:57

3 Answers3

18

Change your select field to <select id="dropDown" autocomplete="off">

j08691
  • 204,283
  • 31
  • 260
  • 272
0

For best browser support it's actually (although it seems so dumb) better to use

autocomplete="nope"

To quote MDN:

In some cases, the browser will keep suggesting autocompletion values even if the autocomplete attribute is set to off. This unexpected behavior can be quite puzzling for developers. The trick to really forcing the no-autocompletion is to assign a random string to the attribute [...] Since this random value is not a valid one, the browser will give up.

GeorgeButter
  • 2,521
  • 1
  • 29
  • 47
-1

It's a binary value, not an attribute (for some reason). Use:

<option selected="selected" value="1">value2</option>

or:

<option selected value="1">value2</option>
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176