views:

701

answers:

3

I have been hitting a brick wall on this for about an hour now. I have a list of counties that I build and add to my view data (counties) and then render the list with a: html.DropDownList('invoice.county', counties) in my view.

It appears to render correctly but FF REFUSES to set the selected item. I have tried swapping the values out for integers (so they don't match the display text) and that did not work. FF just displays the first item in the list

<select id="invoice_county" name="invoice.county">
   ...
   <option value="Lander">Lander</option>
   <option selected="selected" value="Laramie">Laramie</option>
   <option value="Larimer">Larimer</option>
   ...
</select>

I have trimmed the values to the ones surrounding the selected item.

Can anyone give me insight into this????

+1  A: 

If you are using XHTML ...option selected="selected"... is correct. If you are using HTML, it should just be ...option selected... - and this is known to be a problem if you don't get it quite right.

Sohnee
All my code went missing... selected="selected" for XHTML and just selected with no equals sign and no value for HTML. More information here:http://www.w3.org/TR/html4/interact/forms.html#edef-OPTION
Sohnee
+4  A: 

Hi. Firefox has a weird bug/feature that means if you just refresh the page, it will select the option already selected regardless of whether the selected attribute is on another option. For example, if I put in:

<select id="invoice_county" name="invoice.county">
   <option value="Lander">Lander</option>
   <option selected="selected" value="Laramie">Laramie</option>
   <option value="Larimer">Larimer</option>
</select>

Saved and refreshed in Firefox, then put:

<select id="invoice_county" name="invoice.county">
   <option selected="selected" value="Lander">Lander</option>
   <option value="Laramie">Laramie</option>
   <option value="Larimer">Larimer</option>
</select>

instead and just refreshed after saving, it would keep "Laramie" selected. To stop this, try Ctrl-F5 rather than just F5 or refresh.

Francis Gilbert
A: 

I am not exactly sure what happened but it appears to have fixed itself this morning.

Thank you all for your answers.

Andrew Burns