Click to See Complete Forum and Search --> : using data in an array through a site


eddy_eikel
09-19-2003, 03:57 PM
Hi all,:D

i've got some array's...
I want to use the data through the website.
The data is in data.js
the for staments in elm.js
and there is text in text.js with image links.
the array are used to create a Tab element
after loading there's a link panel created with the myArray var
then the Tab's are named with 'test_1' and the Tab page content with the 'A1'.
In the A1 content is text and images the link should be
like "myArray/test/A1/myImage.jpg"
But I just cant get the array past outside the for statement's.

var myArray=new Array('test','test_1','test_2');
var test=new Array('A1','A2','A3','A4');
var test_1=new Array('B1','B2','B3','B4');
var test_2=new Array('C1','C2','C3','C4');
A1="a1";
A2="a2";
A3="a3";
A4="a4";
B1="b1";
B2='b2';
B3='b3';
B4='b4';
C1='c1';
C2='c2';
C3='c3';
C4='c4';
var Link='';

for(var b=0;b<myArray.length;b++){
var n=eval(Array[b]);
for(var q=0;q<n.length;q++){
var u=eval(n[q]);
Link=Array[b]+'/'+n[q]+'/';
alert("this is link ... "+Link);
}
}
alert("this is link ... "+Link);

David Harrison
09-19-2003, 05:15 PM
Firstly n is not an array:

var u=eval(n[q]);

and even if it was, you wouldn't need the eval, same goes for the other eval:

var n=eval(Array[b]);

Another blinding error is that you don't have an array called Array. You have one called myArray if that is the one you were referring to.

Also this line:

Link=Array[b]+'/'+n[q]+'/';

notice the n[q], well if we substitute in what n is we get this:

Array[b][q]

This is a non-existant 2 dimentional array.

So no wonder your code doesn't work, it's riddled with errors. If you tell me what the general effect you're trying to achieve is, I'll write some code for you, or if you would prefer I will simply point you in the right direction.

eddy_eikel
09-20-2003, 02:55 AM
Hi your right, made it work :D
But i still need a way to use the data throughout my site
//////////////////////////////////////////
var myArray=new Array('mysql','php','perl');
var mysql=new Array('A1','A2','A3','A4');
var php=new Array('B1','B2','B3','B4');
var perl=new Array('C1','C2','C3','C4');
var A1=new Array("Atest1");
var A2=new Array("Atest2");
var A3=new Array("Atest3");
var A4=new Array("Atest4");
var B1=new Array("Btest1");
var B2=new Array('Btest2');
var B3=new Array('Btest3');
var B4=new Array('Btest4');
var C1=new Array('Ctest1');
var C2=new Array('Ctest2');
var C3=new Array('Ctest3');
var C4=new Array('Ctest4');
Atest1="A-test1 this is text for the site";
Atest2="A-test2 this is text for the site";
Atest3="A-test3 this is text for the site";
Atest4="A-test4 this is text for the site";
Btest1="B-test1 this is text for the site";
Btest2="B-test2 this is text for the site";
Btest3="B-test3 this is text for the site";
Btest4="B-test4 this is text for the site";
Ctest1="C-test1 this is text for the site";
Ctest2="C-test2 this is text for the site";
Ctest3="C-test3 this is text for the site";
Ctest4="C-test4 this is text for the site";


var Link='';

for(var b=0;b<myArray.length;b++){
var n=eval(myArray[b]);
for(var q=0;q<n.length;q++){
var u=eval(n[q]);
Link=myArray[b]+'/'+n[q]+'/';
alert("this is link inside the for statement... "+Link);
}
}
alert("this is link outside the for statment... "+Link);
/////
the data is used like this ...
nav.panel=createElm(nav,5,((b+1)*24),bodyWidth()/8-14,22);
nav.panel.setHTML('<div class="panel"><a href="javascript:onclick('+myArray[b]+')"><center>'+myArray[b]+'</a></div><br/>');
//baseref=myArray[b];
//src=baseref+'/'+n[q]+'/';
if(i==0){tab.addPage(n[q],u);}
onclick=function(tet){
tab.remove();
tab=Tab(null,null,180,80,820,540,"red");
for(var g=0;g<tet.length;g++){ var r=eval(tet[g]);
//src=baseref+'/'+tet[g]+'/';
tab.addPage(tet[g],r);


///////////////////////////////////////////:rolleyes:

David Harrison
09-20-2003, 05:10 AM
What do you mean by "use the data throughout my site", as long as you don't write over anything in the array all the data is still accessible.

eddy_eikel
09-20-2003, 06:05 AM
What do you mean by "use the data throughout my site", as long as you don't write over anything in the array all the data is still accessible.

Hi :D
That's the problem, I can't use the data out side the for statements after the last '}'.
see the alert message
alert nr. 1 shows the complete array
2 doesn't
:(

the idea is to use data in the array and create all the elements using this data, i also want to make the links to diffrent documents and images using this data.

===============================
array 1 =>> parent 1,p2,p3
array2 => childnode1,C2,C3
array3 => Child-childnode,CC1,CC2

parent
childnode
childnode
loading an external textfile onclick
link=> /parent/childnode/childchildnode/childchildnode_txt.js

and

ImageLink like:
/parent/childnode/childchildnode/this_image_NAME.jpg

so create a couple of array's and
use them through the site to create object names and link and image ref's.

hope you understand what i like to do...







:rolleyes:

eddy_eikel
09-20-2003, 06:21 AM
checkout : mysite (http://home.deds.nl/~daihard/index.html)

goto -> Information
and then AddingFuel or turbo
when you click on
more ->
then a new 'window opens with a long text .
maybe you understand better how i want it to get it working nicely
:D :p :cool:

David Harrison
09-20-2003, 08:11 AM
Next problem, Link is not an array, link is just a variable. This means that on this line:

Link=myArray[b]+'/'+n[q]+'/';

every time the for loop runs Link is assigned a new value. This is why it shows up in the alert in the for loop but outside the loop that alert only show's the last value that was assigned to the variable Link.

I suggest changing the line above, into this:

Link[(n.length-1)*b+q]=myArray[b]+'/'+n[q]+'/';

and before the loop have this;

var Link=new Array();

and if you want to show all of the values assigned to the link array in an alert have this:

alert(Link.join(", "));