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

    Creating and populating multidimensional arrays usings XML

    Hi,
    I have a script which takes data from various multidimensional arrays and prints this content as links into a specific div on the page. (thanks to all who helped on that!). Problem is that the arrays cannot be hardcoded but must be created dynamically. Probably from an XML file.

    The array will ultimately need to look similar to this :

    var myAarray= new Array()
    myAarray=[["amy","21312"],["andy","343423"],["andrew","21312"],["anthony","343423"]]


    this is the function that then prints that array as links:


    function printA(){
    document.getElementById('test').innerHTML = '';
    var root = document.getElementById('test');
    for (i=0; i<myAarray.length; i++){
    var a = document.createElement('a');
    var n = document.createTextNode(myAarray[i][0]);
    var br = document.createElement('br');
    a.setAttribute('href',myAarray[i][1]);
    a.setAttribute('target','_blank');
    a.appendChild(n);
    root.appendChild(a);
    if(i<myAarray.length-1){
    root.appendChild(br)
    }
    }
    }



    Is it possible to create a function that would create these arrays (one for each letter of the alphabet) in the format above, and then once that function is completed to simply call the printA() function?


    Again, any help on this hugely appreciated.

    cheers.

  • #2
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Slight change to the above

    Sorry, but I've since discovered all links can be hardcoded into the header and will not require xml.

    At present I have a separate function for each letter (printA(), printB() etc.)
    which is pretty unwieldly and space consuming. Each of these functions is calling on a seperate array. What I am trying to do is create a single array which contains all entries for all letters, and then adjust the 'print' function so that, depending which letter is selected , it will cycle through the array and print the letter details only related to that selected.

    I really hope this makes sense to someone, as its beginning to make less and less sense to me!


  •  

    Posting Permissions

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