Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

please help; 3 dimensional arrays 2

Status
Not open for further replies.

JeroenB

Programmer
Apr 8, 2001
93
BE
Hi,

I have to make a 3D array; is someone familiar with this or can you give me the url of a good example ?
I also need information on 2D arrays

Thanks in advance
JeroenB
jeroenbekaert@hotmail.com
 
Multidimensional arrays in javascript are just arrays of arrays:

x=new Array([0,1,'a',3,4],[0,1,2,3,4])

x[0][2] is 'a'
x[1][4] is 4

note that d=[0,1,2,3] is systematically equivalent to d=new Array(0,1,2,3) jared@eae.net -
 
Hi JeroenB,

here is an example of 3x3x3 array:

MyArray = new Array(3)
MyArray[0] = new Array(3)
MyArray[0][0] = new Array(3)
MyArray[0][0][0] = "something"
alert(MyArray[0][0][0])

hope this helps, Chiu Chan
cchan@emagine-solutions.com
 
yeh, thanks,
but another poblem is now that I have to make with this array a kind of 3dimensional <select>-tool;
for instance; if region1 is selected, I can choose between 10 countries; and if I then have selected a country and can choose between 10 cities ...
 
// Place[region][countries][cities]
Place = new Array(&quot;North America&quot;,&quot;ASIA&quot;)

// Define Countries in Place[0] or North America
Place[0] = new Array(&quot;USA&quot;,&quot;CANADA&quot;)

// Define Cites in Place[0][0] or USA
Place[0][0] = new Array(&quot;NEW YORK&quot;,&quot;WASHINGTON&quot;,&quot;BOSTON&quot;)

// Alert Place[0][0][0] or New York
alert(Place[0][0][0])

hope this helps Chiu Chan
cchan@emagine-solutions.com
 
PepperPepsi, thaks a lot for your help;

but I still have a problem (as I'm not a great expert in javaScript);
Once I've defined this array; how can I then do the following :

In my html page I have three <select> boxes; (this equals the three dimensions in my array). So once I have chosen a region, I can choose a country in the second one and the I can choose a city in the third...
But once I change back my region the other two <select> boxes should be resetted....so I can start over again...

Can You help me out...
Thanks in advance

JeroenB
 
ChiuChan;
Thank you for being so helpful
You are the best !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top