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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:34:24+00:00 2026-05-23T09:34:24+00:00

I am currently attempting to set up a set of chained selects using the

  • 0

I am currently attempting to set up a set of chained selects using the Flexbox Jquery plugin (this is not specifically designed for chaining, but can be used for that).

I have the chaining working if I set everything explicitly, but I am trying to dry my code up and make it more understandable. As such, I have come up with the code below.

All boxes currently load initially, and make their queries. The problem I am having is that when I iterate through the menus (as below), I lose the onSelect functionality – it only fires for the last menu I loaded.

My understanding was that since I am using a different JQuery selector each time – $('#' + fbMenu.divId) – it would not matter that I then set the onSelect behavior for another menu, but evidently this is not the case. Am I somehow overwriting the binding each time I am loading a box?

Hopefully I don’t have to specify the onSelect functionality for each dropdown, as there could be a large number of them.

Many thanks for any assistance you can provide!

$(document).ready(function() {  

    // Create the variables for data objects  
    var vehicleMakeFb = new Object();
    var vehicleModelFb = new Object();
    var vehicleTrimFb = new Object();

    // Set up each menu with the divId, jsonUrl and the chlid menus that will be updated on select
    vehicleMakeFb.divId = 'vehicle_vehicleMake_input';
    vehicleMakeFb.jsonUrl = '/vehicles/getmakes';
    vehicleMakeFb.children = [vehicleModelFb];

    vehicleModelFb.divId = 'vehicle_vehicleModel_input';
    vehicleModelFb.jsonUrl = '/vehicles/getmodels';
    vehicleModelFb.children = [vehicleTrimFb];

    vehicleTrimFb.divId = 'vehicle_vehicleTrim_input';
    vehicleTrimFb.jsonUrl = '/vehicles/gettrims';
    vehicleTrimFb.children = [];

    // Create an array of all menu objects so that they can be iterated through
    var allMenus = [vehicleMakeFb,vehicleModelFb,vehicleTrimFb];

    // Create the parent menu
    for (var i = 0; i < allMenus.length; i++) {
        var fbMenu = allMenus[i];
        alert(fbMenu.divId);
        $('#' + fbMenu.divId).flexbox(fbMenu.jsonUrl + '.json', {  

            // Update the child menu(s), based on the selection of the first menu
            onSelect: function() {  

                    for (var i = 0; i < fbMenu.children.length; i++) {
                        var fbChild = fbMenu.children[i];
                        var hiddendiv = document.getElementById(fbMenu.divId + '_hidden');
                        var jsonurl1 = fbChild.jsonUrl + '/' + hiddendiv.getAttribute('value') + '.json';
                        alert(jsonurl1);
                        $('#' + fbChild.divId).flexbox(jsonurl1);   
                    }

            }

        });
    }

});
  • 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-23T09:34:24+00:00Added an answer on May 23, 2026 at 9:34 am

    If you put all the information on the elements them selves i think you will have better results. Although I’ve been known to be wrong, I think the context of the select functions are getting mixed up.

    instead of setting up each menu as an object try:

    $(document).ready(function() {  
    
        var setupdiv = (function(divId, jsonUrl, children)
        {
            jQuery('#' + divId)
                .data("jsonurl", jsonUrl)
                .data("children", children.join(",#"));
        
            // Create the parent menu
            jQuery('#' + divId).flexbox(jsonUrl + '.json', 
            {  
                // Update the child menu(s), based on the selection of the first menu
                onSelect: function() 
                {  
                    var children = jQuery(this).data("children");
                    var jsonUrl = jQuery(this).data("jsonurl");
                    if(children)
                     {
                         children = jQuery('#' + children);
                         alert('children was true');
                     }
                     else
                     {
                         children = jQuery();
                         alert('children was false');
                     }
                     var hiddendiv = jQuery('#' + this.id + '_hidden');
                     children.each(function()
                     {
                         var childJsonUrl = jsonUrl + '/' + hiddendiv.val() + '.json';
                         alert(childJsonUrl);
                         $(this).flexbox(childJsonUrl);   
                     });
                 }
    
             });
        });
        setupdiv('vehicle_vehicleMake_input', '/vehicles/getmakes', ['vehicle_vehicleModel_input']);
    
        setupdiv('vehicle_vehicleModel_input', '/vehicles/getmodels', ['vehicle_vehicleTrim_input']);
    
        setupdiv('vehicle_vehicleTrim_input', '/vehicles/gettrims', []);
    });
    

    DISCLAIMER

    I’m known for my spelling mistakes. Please spellcheck before using this code 😉

    Update

    I’ve changed the first two lines of code and I’ve normalized the indenting as there were a mix of tabs and spaces. Should be easier to read now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently attempting to retrieve a list of objects from my database using jQuery.
I am currently attempting this question : A Pythagorean triplet is a set of
I am currently tinkering with SIMBL, attempting to make my own plugin. I am
I'm currently attempting to set up background audio for an app I'm developing for
I'm attempting to change the wrapper width on a wordpress blog. It's currently set
I'm using Perforce with Vim on Windows. I currently have an auto command set
I am currently attempting to implement a custom gridview interface to display data from
I'm currently attempting to migrate a legacy VBA/Microsoft Access application to Python and PyQt.
I am currently attempting to use Lucene to search data populated in an index.
I'm currently attempting to code one for part of a college project - binary/hex

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.