PDA

View Full Version : Multidimensional array error in IE



junho
12-10-2004, 06:48 AM
Hi,
the following script uses a multidimensional array to print a particular array's contents into a specific div when a button image is clicked. The script works fine in most browsers, but IE (pc) continues to throw up an error :

"myArray[...][...].0' is null or not an object"


It only does this if the number of 'inner' arrays is greater than 3. Anything less than that and the error disappears.

Anyone have any ideas what would be causing this? Any help on this would be hugely appreciated.

<html>
<head>

<script language="javascript">
var myArray= new Array()
myArray=[
[["amy","21312"],["andy","343423"],["andrew","21312"]],
[["bmy","21312"],["bandy","343423"],["bandrew","21312"]],
[["cmy","21312"],["candy","343423"],["candrew","21312"]],
[["dmy","21312"],["dandy","343423"],["dandrew","21312"]],
[["emy","21312"],["eandy","343423"],["eandrew","21312"]]
]



var i;
var j;




function print(j){
document.getElementById('test').innerHTML = '';
var root = document.getElementById('test');
for (i=0; i<myArray.length; i++){
var a = document.createElement('a');
var n = document.createTextNode(myArray[j][i][0]);
var br = document.createElement('br');
a.setAttribute('href',myArray[j][i][1]);
a.setAttribute('target','_blank');
a.appendChild(n);
root.appendChild(a);
if(i<myArray.length-1){
root.appendChild(br)
}
}
}
</script>
</head>
<body>
<a href="javascript:print(0)">A</a>
<a href="javascript:print(1)">B</a>
etc.

<div id="test"></div>
</body>
</html>




.... hope this all makes sense. thanks again!