Hi,
the problem is that the innerHTML attribute of a select element cannot be set in IE. It does not cause an error, but it does not work.
The following example does not work in IE, but it works in Firefox, Chrome, Safari and Opera:
Code:
<head>
<script>
function Init () {
var response = "<option>1</option><option>2</option>";
var select = document.getElementById ("mySelect");
select.innerHTML = response;
}
</script>
</head>
<body onload="Init ()">
<select id="mySelect"></select>
</body>
A possible solution if the ajax response is a comma separated list of values and texts ("value1,text1,value2,text2, ...") and the options are created one by one:
Code:
<head>
<script>
function Init () {
var response = "value1,text1,value2,text2";
var responseArr = response.split (",");
var select = document.getElementById ("mySelect");
for (var i = 0; i < responseArr.length; i+=2) {
var option = new Option (responseArr[i+1], responseArr[i]);
select.options.add (option);
}
}
</script>
</head>
<body onload="Init ()">
<select id="mySelect"></select>
</body>
Related links:
Option object,
options collection.