...

View Full Version : Multi-dimensional array function error in IE



rasoodock
12-09-2004, 08:55 PM
Hi. IE has been throwing up an error on the following function. The function which is called when a user clicks on a letter img in the body of the page.
eg:

<a href="javascript:print(0)">A</a>
<a href="javascript:print(1)">B</a>
etc.

the function then prints the contents of the inner array to a specific div.
It's all working fine except for an error in IE:

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

I just can't seem to get rid of this error. Here's the code:


var myArray= new Array()
myArray=[
[["amy","21312"],["andy","343423"],["andrew","21312"]],
[["bmy","21312"],["bandy","343423"],["bandrew","21312"]],
[["cmy","21312"],["candy","343423"],["candrew","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)
}
}
}


thanks for taking the time.

rasoodock
12-09-2004, 08:58 PM
sorry, the tongue icons were NOT intentional.

aifilaw
12-09-2004, 10:16 PM
works fine ...


<script type="text/javascript">
var myArray= new Array()
myArray=[
[["amy","21312"],["andy","343423"], ["andrew","21312"]],
[["bmy","21312"],["bandy","343423"],["bandrew","21312"]],
[["cmy","21312"],["candy","343423"],["candrew","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>

<a href=javascript:print(0)>A</a>
<a href=javascript:print(1)>B</a>

<div id=test name=test></div>

rasoodock
12-09-2004, 11:18 PM
Yes, it seems to work fine when there are only up to 3 'inner' arrays. However anything more than that (which I will certainly need) throws up the error in IE.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum