title: Select drop down sort order in IE8
body: <p>I have a select drop down on a web form, that is populated based on options selected in input fields prior to this on the form.</p>
  
  <p>The form uses AJAX/JSON to get the list of options back from the server which it will use to populate the select.</p>
  
  <p>I have a loop in my Javascript code that loops over the JSON response object in order to populate the select.</p>
  
  <p>The response object will have data in the form of key/value pairs (both string values) as such:</p>
  
  <p>" " - Please select, 45 - Optical, 52 - Dental, 67 - Surgery, 83 - Osteopath etc etc..</p>
  
  <p>The code to populate the select I am using is:</p>
  
  <pre><code>$.each(response, function(key,value) {
      $("#benefitField4").append("&lt;option value="+key+"&gt;"+value+"&lt;/option&gt;");
  }
  </code></pre>
  
  <p>... where 'benefitField4' is the id of the select on the form.</p>
  
  <p>I need the results in the select shown in key order, so with 'Please select' having a key value of " ", I would hope this would be first.</p>
  
  <p>Now in all browsers the resulting select displays the drop down in the right order, with 'Please select' being the first option.</p>
  
  <p>In IE8 however, 'Please select' is 3rd in the list, with 'Optical' being first.</p>
  
  <p>I have tried sorting the select by using this code:</p>
  
  <pre><code>var selectList = $('#benefitField4 option');
  selectList.sort(function(a,b){
  a = a.value;
  b = b.value;
  return a-b;
  });
  $('#benefitField4').empty()
  $('#benefitField4').eq(0).html(selectList);
  </code></pre>
  
  <p>But this results in the last item in the select being shown (in this case Osteopath) as the initial value in the select, with 'Please select' being the last. Again, only in IE8. </p>
  
  <p>As I need this to work in all browsers, I'm a bit lost as to why IE8 is behaving this way.</p>
  
  <p>Can anyone help please?</p>