Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7903613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:47:21+00:00 2026-06-03T09:47:21+00:00

My problem: I know it may sound funny, but here’s my problem: I have

  • 0

My problem:

I know it may sound funny, but here’s my problem: I have a select that is populated through Ajax on success in the following way:

$.each(data, function(key, value) {
            options += '<option value="' + key + '">' + value + '</option>';
        });

My server returns a sorted map (sorted by value). All works fine, but in Internet Explorer (7,8 and 9) the select appears unsorted.

What I’ve found :

What I’ve found is that IE actually displays it sorted by the key I am passing to the value parameter. My list is sorted on the back-end by value, and I want to display it like that (working fine on Chrome, Firefox, etc).

I am thinking that most probably the cause of this sorting is the $.each jQuery function. Maybe it is iterating by the key? I am not sure about this, though, so I would like some feedback. Also, how can I make an alternative iteration on the map, to make sure of this? I am trying to avoid to perform a jQuery sorting, as the sorting is done in the back-end.

I am mentioning that I need the key and value passed to the option the way that I am passing them.

Edit – an example:

How it should be (and is on Chrome and Firefox):

<option value="13">A</option>
<option value="2">B</option>
<option value="55">C</option>

How it is in IE:

<option value="2">B</option>
<option value="13">A</option>
<option value="55">C</option>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:47:22+00:00Added an answer on June 3, 2026 at 9:47 am

    Your problem is that objects don’t actually have a specific ordering of key/value pairs. IE is not wrong in changing it. Use an array to hold the pairs instead, something like:

    [
        {
            "value": "13",
            "text": "A"
        },
        {
            "value": "2",
            "text": "B"
        },
        {
            "value": "55",
            "text": "C"
        }
    ]
    

    And loop through it as follows:

    $.each(data, function(index, option) {
        options += '<option value="' + option.value + '">' + option.text + '</option>';
    });
    

    Finally, you shouldn’t manipulate HTML as a string to build elements. Use the DOM. I imagine you have someElement.html(options); somewhere? Well instead, make options = someElement;, and do this:

    $.each(data, function(index, option) {
        options.append(
            $('<option>').prop('value', option.value).text(option.text)
        );
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this may sound crazy, but I swear that on two separate ocassions
I know that can co-exists with web form no problem as Hanselman mention here
I know it may seem like an easy to solve problem, but I can't
I know it may sound very strange, but I need to know if there
I know the title may sound a little weird, but the same goes for
I'm facing a problem where I know the root cause but don't see a
I know I've solved this problem before, but I can't remember or find the
I know how to fix the problem, but the thing is, my .android directory
I know it may be simple question to all experienced developer.. I have trapped
I know this may not be exactly a coder question, but I feel it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.