Reputation: 51
I get a Javascript error only in IE8. Chrome, FF & IE9+ work perfectly.
The error in IE8 is: 'type[...][...]' is null or not an object
Basically the Size field is populated with various values, once selecting the value the Type and Code fields are changed to the corresponding values in the Array. Any ideas as to why IE8 just does not want to play along?
The error also refers to the following line in the code below:
typelist.options[typelist.options.length]= new Option(type[selectedproduct][i].split("|")[0],type[selectedproduct][i].split("|")[1])
Thanks.
Code:
<form name="products">
<table >
<tr>
<td width="65px">Size</td>
<td>
<select name="size" onChange="updatetype(this.selectedIndex)" style="width:120px;">
<option value="A26-0015">Large</option>
<option value="A26-0016">Small</option>
</select>
</td>
</tr>
<tr>
<td width="65px">Type</td>
<td>
<select name="type" onChange="updatecode(this.options[this.options.selectedIndex].value)"></select>
</td>
</tr>
<script type="text/javascript">
var type=new Array()
type[0]=["Blue|A26-0015",];type1[1]=["Green|A26-0016",];
</script>
<tr>
<td>Code</td>
<td><input type="text" value="A26-0015" name="code" readonly="readonly" ></td>
</tr>
</table>
</form>
<script type="text/javascript" >
var sizelist=document.products.size
var typelist=document.products.type
var codelist=document.products.code
updatetype(0);
function updatetype(selectedproduct){
typelist.options.length=0
if(selectedproduct>-1){
for (i=0; i<type[selectedproduct].length; i++){
typelist.options[typelist.options.length]= new Option(type[selectedproduct][i].split("|")[0],type[selectedproduct][i].split("|")[1])
}
}
updatecode(typelist.value)
}
function updatecode(code){
codelist.value = code
}
</script>
Upvotes: 1
Views: 2177
Reputation: 10148
I'd start by removing null values from your arrays:
type[0]=["Blue|A26-0015",];
^----- trailing comma
Upvotes: 1