Can someone explain why this code works in FF, but fails in MSIE?
In particular the content / display of the <select> options.
What is different in the executions of the same script on different browsers?
What can I do or change to make it work in both browsers?
[code]
<html>
<head>
<title> Pass array by reference </title>
<script type=”text/javascript”>
var ClassOf2010 = [
‘John Jacob Jingleheimer Smith’,
‘Alice Wonderland’,
// … etc …
‘Seymore Butts’
];
var ClassOf2011 = [
‘Gasoline Alley’,
‘Betty Boop’,
‘Clarabel Cow’,
‘Deputy Dog’,
// … etc …
‘Elmer Fudd’
];
function showArray(List) { return List.join(‘n’); }
function $_(IDS) { return document.getElementById(IDS); }
function AddOptionItem(IDS,Item) {
Item.trim();
var sel = $_(IDS);
var tmp = Item.split(‘:’);
sel.options[sel.options.length]=new Option(tmp[0],Item,true,true);
}
function initStudentSBox(IDS,List) {
$_(IDS).options.length = 0;
$_(IDS).options[0]=new Option(‘Choose’,’:blank’,true,true);
for (var i=0; i<List.length; i++) { AddOptionItem(IDS,List[i]+’:’+i); }
$_(IDS).selectedIndex = 0;
}
onload = function() {
initStudentSBox(‘Studs2010’,ClassOf2010);
initStudentSBox(‘Studs2011’,ClassOf2011);
}
</script>
</head>
<body>
<button onclick=”alert(showArray(ClassOf2010))”>Show Class of 2010</button>
<select id=”Studs2010″ onchange=”alert(this.value)”></select>
<p>
<button onclick=”alert(showArray(ClassOf2011))”>Show Class of 2011</button>
<select id=”Studs2011″ onchange=”alert(this.value)”></select>
</body>
</html>