0

I have a strange problem. Everything works fine in Chrome/Firefox, but IE is bugging me. I have a simple triple dropdown to show a date. If the user already has filled in a date in the database this one will be shown whenever they load the page.

nDate = new Date(date);
d = nDate.getDate();
m = nDate.getMonth();
m++;
y = nDate.getFullYear();
$("#DAY").val(d);
$("#MONTH").val(m);
$("#YEAR").val(y);

My variable date is defined, 100% sure it gets filled in since it works fine in other browsers.

The format is: 'YYYY-MM-DD'

Now the strange part is, if I print the values of the dropdown, they are shown correctly. So basically the dropdown has the right value selected, it just doesn't get shown. Anybody has an idea why?

Thx in advance.

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132

1 Answers1

0

I think you need to set the selected index property of the select.

e.g.

var d = nDate.getDate();
var daySel = $("#DAY")[0];
for(var i = 0; i < daySel.options.length; ++i) {
    if(daySel.options[i].value == d) {
       daySel.selectedIndex = i;
       break;
    }
}

JS Fiddle: http://jsfiddle.net/7fApu/

row1
  • 5,568
  • 3
  • 46
  • 72
  • Probably related to this http://stackoverflow.com/questions/47824/how-do-you-remove-all-the-options-of-a-select-box-and-then-add-one-option-and-se/2040837#2040837 – row1 Mar 27 '14 at 10:30