Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-09-2004, 07:55 PM   PM User | #1
rasoodock
New to the CF scene

 
Join Date: Dec 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
rasoodock is an unknown quantity at this point
Multi-dimensional array function error in IE

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="javascriptrint(0)">A</a>
<a href="javascriptrint(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 is offline   Reply With Quote
Old 12-09-2004, 07:58 PM   PM User | #2
rasoodock
New to the CF scene

 
Join Date: Dec 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
rasoodock is an unknown quantity at this point
sorry, the tongue icons were NOT intentional.
rasoodock is offline   Reply With Quote
Old 12-09-2004, 09:16 PM   PM User | #3
aifilaw
New Coder

 
Join Date: Dec 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
aifilaw is an unknown quantity at this point
works fine ...

Code:
<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>
aifilaw is offline   Reply With Quote
Old 12-09-2004, 10:18 PM   PM User | #4
rasoodock
New to the CF scene

 
Join Date: Dec 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
rasoodock is an unknown quantity at this point
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.
rasoodock is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:43 PM.


Advertisement
Log in to turn off these ads.