1

I got this working fine in Chrome. If a user has a state or country associated with their account, the state or country gets programmatically pre-selected and gets displayed as the default value in the dropdowns.

But in firefox, while these values get selected, the visible selection still displays as -State- and -Country- (when the dropdown is contracted). When you expand these dropdowns, the correct values are selected. How do I make these display as the selection in Firefox when the menus are contracted? Thanks!

Wes
  • 1,183
  • 3
  • 23
  • 51

1 Answers1

0

I had a list like this:

<select name="<?=$mode?>AcctCountry" id="<?=$mode?>AcctCountry" class="select2 input-block-level">
    <option value="" selected="selected">-Country-</option>
    <option value="US">United States</option>
    <option value="AF">Afghanistan</option>
    <option value="AX">Åland Islands</option>
    <option value="AL">Albania</option>
    <option value="DZ">Algeria</option>
    ...

I got rid of selected="selected" on the first option and this solved all my Firefox problems. If you keep that there and try to change the value using jQuery using any method, Firefox will still display the selected="selected" option but not Chrome.

Why is FF becoming the new IE? Ugh.

Wes
  • 1,183
  • 3
  • 23
  • 51
  • First of all, you shouldn't answer your own question like this :) Secondly, take a look at this answer: http://stackoverflow.com/questions/17856523/how-to-set-the-selected-option-of-a-select-dropdown-list-with-jquery Also: It's probably not firefox's fault – Johan Lindskogen Dec 16 '13 at 22:04
  • I don't see how it's not firefox's fault when Chrome handles this properly and FF does not. If I change the selection using jquery, ff should adjust the displayed selection accordingly (which Chrome does). – Wes Dec 16 '13 at 22:11
  • What code are you using to change the selected option? – Johan Lindskogen Dec 16 '13 at 22:19
  • I think I tried every possible jQuery method at some point. Using val(), attr(), prop(), etc. FF was changing the values but was not displaying them as selected (when the dropdown is contracted). Chrome was not having this issue. – Wes Dec 16 '13 at 22:20
  • What do you mean with 'displaying as selected'? – Johan Lindskogen Dec 16 '13 at 22:24
  • @Ndushi: *why* should he not 'answer [his] own question like this'? Answering your own question is perfectly accepted behaviour on SE, so long as the question is a valid question and the answer is a valid answer. – David Thomas Dec 17 '13 at 22:43
  • @DavidThomas Oops, I never realized that was the solution to his question, I just thought he provided more information for me... – Johan Lindskogen Dec 19 '13 at 21:05