Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 947917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:09:30+00:00 2026-05-15T23:09:30+00:00

I am trying to build a 3D Javascript array, but I am unsure of

  • 0

I am trying to build a 3D Javascript array, but I am unsure of how to do it, basically I have 3 arrays, Provinces, Cities and Malls all in succession, so I want to create a 3D array to store all the data in and then write some jQuery/Javascript to get out what I need.

I have a script that can populate a drop down list with array items, but now I am adding an extra dimension to it and I am getting a little confused as to how to proceed, here is the code I have thus far,

The jQuery:

<script>
    model[0] = new Array( 'Arnage', 'Azure', 'Brooklands', 'Continental', 'Corniche', 'Eight', 'Mulsanne', 'Series II', 'Turbo R', 'Turbo RT');
    model[1] = new Array( '412', '603', 'Beaufighter', 'Blenheim', 'Brigand', 'Britannia');
    model[2] = new Array( 'Inyathi', 'Rhino');
    model[3] = new Array( 'Amandla', 'Auto Union', 'Horch');

            function makeModel(obj){

            var curSel=obj.options[obj.selectedIndex].value ;
            var x;

            if (curSel != 'null'){


                $('#model').css({'display' : 'block'});

                $('#model').html("<select name='model' id='sub'>");
                for (x in model[curSel])
                {

                    $('#sub').append("<option value='" + model[curSel][x] + "'>" + model[curSel][x] + "</option>");
                }

            }else{
                $('#model').css({'display' : 'block'});
            }
        }

</script>

The HTML:

<form>
<p>
<span class='left'><label for='make'>Make: </label></span>
<span class='right'><select name='make' id='make' onchange='makeModel(this);'>
<option value='0'>Select one</option>
<option value='1'>one</option>
<option value='2'>two</option>
<option value='3'>three</option>
<option value='4'>four</option>
</select>
</span>
</p>
<p>
<div id='model'></div>
</p>
</form>

So as you can see, the above code generates a drop down menu of models depending on what make I select, now what I want to achieve now is adding one more level to it, so they will click on a province, then the cities drop down will appear, and when they choose a city, the malls will appear.

What would be the best way of approaching this?

Thanx in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:09:31+00:00Added an answer on May 15, 2026 at 11:09 pm

    If you have a structure like this one

    var provinces = [
       { name: "Province A", cities: [
            { name: "City A.A", malls: [
               { name: "Mall A.A.1" },
               { name: "Mall A.A.2" }
            ] },
            { name: "City A.B", malls: [
               { name: "Mall A.B.1" }
            ] }
       ] },
       { name: "Province B", cities: [
            { name: "City B.A", malls: [
               { name: "Mall B.A.1" },
               { name: "Mall B.A.2" }
            ] },
            { name: "City B.B", malls: [] }
       ] }
    ];
    

    Then you can populate the dropdowns like so:

    function populateDropdown(drop, items) {
       drop.empty();
       for(var i = 0; i < items.length; i++) {
          drop.append('<option value=' + i + '>' + items[i].name + '</option>');
       }
       drop.show();
    }
    
    populateDropdown( $('#provinces'), provinces );
    

    And upon an action:

    $('#provinces').change(function() {
       var provinceIndex = $(this).val();
       var province = provinces[provinceIndex];
    
       populateDropdown( $('#cities'), province.cities );
    
       $('#malls').hide();
    });
    
    $('#cities').change(function() {
       var provinceIndex = $('#provinces').val();
       var province = provinces[provinceIndex];
    
       var cityIndex = $(this).val();
       var city = province.cities[cityIndex];
    
       populateDropdown( $('#malls'), city.malls );
    });
    

    EDIT

    If the data structure on top looks hard to read, by the way, it’s the exact same thing as the following:

    var provinces = [];
    
    // populate provinces
    provinces.push({ name: "Province A", cities: [] });
    provinces.push({ name: "Province B", cities: [] });
    
    // populate cities
    provinces[0].cities.push({ name: "City A.A", malls: [] });
    provinces[0].cities.push({ name: "City A.B", malls: [] });
    provinces[1].cities.push({ name: "City B.A", malls: [] });
    provinces[1].cities.push({ name: "City B.B", malls: [] });
    
    // populate malls
    provinces[0].cities[0].malls.push({ name: "Mall A.A.1" });
    provinces[0].cities[0].malls.push({ name: "Mall A.A.2" });
    provinces[0].cities[1].malls.push({ name: "Mall A.B.1" });
    provinces[1].cities[0].malls.push({ name: "Mall B.A.1" });
    provinces[1].cities[0].malls.push({ name: "Mall B.A.2" });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My opinion, for what it's worth, is that de-normalisation is… May 16, 2026 at 4:06 pm
  • Editorial Team
    Editorial Team added an answer Stupid case. While moving the app from Rails2 to Rails3… May 16, 2026 at 4:06 pm
  • Editorial Team
    Editorial Team added an answer Change it from using IDs, which must be unique to… May 16, 2026 at 4:06 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to build an array in javascript that contains a list of ids.
I'm trying to build a list of phrases using an array of word lists.
I'm somewhat new to object oriented programming in Javascript and I'm trying to build
I'm trying to build a form using the Zend_Form component, but the number of
I am trying to build some sort of a javascript antivirus that would try
I'm trying to post a JavaScript data object with the following: $.post(frm.attr(action), data, function(res)
I am using fluent NHibernate with WebForms and I am trying to build a
I am trying to replace the JavaScript onclick event handler in ASP.NET that is
I'm trying build my application using REST and Spring MVC. For some entities I
Trying to build a legacy code in VS2005 and get errors in VC header

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.