So I have this following code that works great for every browser I’ve tested so far, except IE
var array = eval( '(' + xmlHttp.responseText + ')' );
var html = '';
for(var key in array)
{
html += '<option value="' + key + '">' +array[key] + '</option>';
}
alert(html);
document.getElementById('countries').innerHTML = html;
The problem stands at the .innerHTML. The alert prints the data as it should be, but the inner strips the tag and I end up with words in a row.
So, any ideas how to possibility fix that issue?
It’s a known issue that IE doesn’t let you use
.innerHTMLto setoptionelements in aselect.You should be creating elements using DOM methods instead.
And if
arrayis an actual Array, then useforinstead offor-inin JavaScript.And if you need to empty the
selectfirst, you can do that with.innerHTML = "", or better, with a loop: