rasoodock
12-09-2004, 12:10 PM
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.
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.