Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, the tongue icons were NOT intentional.

  • #3
    New Coder
    Join Date
    Dec 2004
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>

  • #4
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •