In IE9 I am getting an error Microsoft JScript runtime error: 'populatedropdown' is undefined on the line <input type="button"....
I assume I am not escaping the literal values correctly. How should I change?
<html>
<head>
<title>Add items to dropdown</title>
<script type="text/javascript">
function populatedropdown(var devicelist) {
var devList = document.frm.optdevices;
var arrDev = split(devicelist, ";");
devList.options.length = 0; // this removes existing options
for (var i = 0; i <= 3; i++) {
var option = new Option(arrDev[i],i);
devList.options[i] = option;
}
}
</script>
</head>
<body>
<form name="frm">
<select name="optdevices">
</select>
<input type="button" value="TestAdd" onclick="populatedropdown('201;202;203;')" />
</form>
</body>
</html>
Unexpected token varon the first line of script. Also, separate your JavaScript from your HTML (attach event listeners on page load).