Well, the actual size retrieval and option appending should be working fine as far as I can see, while what I interpret as an intention to clear the size select element of options does not.
That is, if you ever call the function with an empty string as argument, this part should give you an error
var s = d.getElementById('size');
if (str==""){
s.appendChild("");
return;
}
domelement.appendChild() takes another domelement, sometimes restricted to some appropriate type, as argument. If you really did want to append an empty string to a select element, that would have to be an option containing an empty string
if (str==""){
var o = d.createElement('option');
o.value='';
o.appendChild(d.createTextNode(''));
s.appendChild(o);
return;
}
But I entirly fail to see the point of adding empty options. Also, if your intent is to clear out the select element of existing options, it would make more sense to use one of two possibilities to do this that I posted earlier, and use that in the ajax onreadystatechange event handler function instead. Which means you should remove the if block for "if (str ='')" completely.
Without the second line in the code below, you'd continue to add more and more options to the select element each time, rather than replace the previous set of options.
var sizes = eval('('+xmlhttp.responseText+')');
s.options.length = 0; // This is one of the two ways I suggested for doing this
for (key in sizes) {
And the full code I used to test yours in IE8, without trouble, was
selectSize.php
header('content-type: text/plain; charset=utf-8');
$sizeArray = array('Please select pool size', 2, 5, 8, 13);
echo json_encode($sizeArray);
exit;
html and javascript
<script type="text/javascript">
function showPoolSize(str){
var d = document;
var s = d.getElementById('size');
loadScript("a_test.php?Pool_Shape="+str,function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
var sizes = eval('('+xmlhttp.responseText+')');
s.options.length = 0;
for (key in sizes) {
var o = d.createElement('option');
o.value = key;
var text = d.createTextNode(sizes[key]);
o.appendChild(text);
s.appendChild(o);
}
}
});
}
//Ajax Http request function
function loadScript(url,cfunc){
// var xmlhttp = null;
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else if(window.XMLHttpRequest){// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
</script>
</head>
<body style="margin: 40px;">
<select id="size"></select>
<input type="button" onclick="showPoolSize('shape1');" value="Fill select"/><br/>
</body>
So as I expected from reading your code, there was no problem in IE8.