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 6943203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:07:31+00:00 2026-05-27T13:07:31+00:00

I have been given an array in the following format and need to put

  • 0

I have been given an array in the following format and need to put it into two drop down boxes one with make and the other with model based on the first selection. (the actual array is huge, but I have just included the first few)

var aMember = [{
    "Make": "other",
    "Models": ["other"]
}, {
    "Make": "Boat",
    "Models": ["Over 21 ft.", "Under 21 ft."]
}, {
    "Make": "Motorcycle",
    "Models": ["Over 600cc", "Under 600cc"]
}];

I need to have a make combo box with Other, Boat and Motorcycle, which when selected populates the second combo box with the options.

I have done almost no JavaScript before, but have tried the following, which does not work.
I really don’t know if I am anywhere near to what I need.

<html>
<head>
<script>
var cars =[{"Make":"other","Models":["other"]},{"Make":"Boat","Models":["Over 21 ft.","Under 21 ft."]},{"Make":"Motorcycle","Models":["Over 600cc","Under 600cc"]}];

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

populateDropdown( $('#Makes'), cars );


$('#Models').change(function() {
   var modelIndex = $(this).val();
   var model = Models[modelIndex ];

   populateDropdown( $('#Models'), cars.Models);

});

</script>
</head>
<body onload = "populateDropdown( $('#Makes'), cars );">
<form>


MAKE:
<select name = 'Makes'>
</select>
MODEL:
<select name = 'Models'>
</select>

</select>
</form>
</body>
</html>  

Thanks

  • 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-27T13:07:32+00:00Added an answer on May 27, 2026 at 1:07 pm
    • You can use $.grep to filter out the current make, and then fetch the models of that make.
    • You can use $.map to map the array with all data to an array of makes.
    • $.each can be used.
    • You can use $("<option>").val(...).text(...) to build the option a little cleaner.
    • You need $(function() {...}) to wait until the DOM is ready.
    • drop.show() is not needed since both selects are already visible
    • You’re populating Models on Models‘s change event. I think you mean to run that on Makes‘s change event.
    • You’re using name instead of id. Also you should not use spaces around the = in HTML attributes.

    This is a corrected version: http://jsfiddle.net/zJTnw/1/.

    $(function(){
        var cars = [
            {"Make":"other",
             "Models": ["other"]},
    
            {"Make":"Boat",
             "Models": ["Over 21 ft.","Under 21 ft."]},
    
            {"Make":"Motorcycle",
             "Models": ["Over 600cc","Under 600cc"]}
        ];
    
        function populateDropdown(drop, items) {
            drop.empty();
    
            $.each(items, function(i, v) { // `i` is index, `v` is element
                drop.append($("<option>").val(v).text(v));
            });
        }
    
        populateDropdown($('#Makes'), $.map(cars, function(x) {
            return x.Make; // map `cars` to an array of makes
        }));
    
        $('#Makes').change(function() {
            var make = $(this).val();
    
            var item = $.grep(cars, function(x) { // get item of this make
                return x.Make === make;
            });
    
            populateDropdown($('#Models'), item[0].Models); // populate with models
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two questions regarding array: First one is regarding following code: int a[30];
I have a Width and Height parametr. I have been given an array of
I have been given a requirement where I need to support multiple databases in
I have been given two different Microsoft Word document that my virus scanner has
I have been given a specification that requires the ISO 8601 date format, does
I have been given the following request. Please give 7% of the current contacts
I have been given a header with the following declaration: //The index of 1
I have been given a DLL (InfoLookup.dll) that internally allocates structures and returns pointers
I have been given the task of internationalizing a large client-server application. The remit
I have been given the option to either have a Windows laptop or a

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.