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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:01:21+00:00 2026-05-15T02:01:21+00:00

I am trying to create multiple dependent dropdowns (selects) with a unique way. I

  • 0

I am trying to create multiple dependent dropdowns (selects) with a unique way. I want to restrict the use of selectors and want to achieve this by using a single class selectors on all SELECTs; by figuring out the SELECT that was changed by its index. Hence, the SELECT[i] that changed will change the SELECT[i+1] only (and not the previous ones like SELECT[i-1]).

For html like this:

<select class="someclass">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
</select>

<select class="someclass">
</select>

<select class="someclass">          
</select>

where the SELECTs other than the first one will get something via AJAX.

I see that the following Javascript gives me correct value of the correct SELECT and the value of i also corresponds to the correct SELECT.

$(function() {
    $(".someclass").each(function(i) {
        $(this).change(function(x) {
            alert($(this).val() + i);
        });
    });         
});

Please note that I really want the minimum selector approach. I just cannot wrap my head around on how to approach this. Should I use Arrays? Like store all the SELECTS in an Array first and then select those?

I believe that since the above code already passes the index i, there should be a way without Arrays also.

Thanks a bunch.
AJ

UPDATE:

Here is somewhat better description:

  1. There are more than 2 `SELECT`s on the page with class `someclass`. SELECT[0] has some values initially and its successors are empty as they will change based on the value of their respective immediate ancestor.
  2. If there is a change in `SELECT[i]`, it fires an event and `SELECT[i+1]` is populated with appropriate `OPTION`s.
  3. `SELECT[i+2]` and further successors are reset if they had any data before. So, only immediate child is populated but further successors are reset.

I hope I articulated well. Please let me know if you need more clarification on what I want.

  • 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-15T02:01:22+00:00Added an answer on May 15, 2026 at 2:01 am

    EDIT: Corrected version.

    $(function() {
        var $all = $('.someclass');              // Reference all the selects
        var last = $('.someClass').length - 1;   // Store index of last select
    
         $(".someclass").change(function() {
    
            var $th = $(this);           // Reference the changed select
    
            var index = $all.index($th);     // Grab the index of the changed select
    
            if(index != last) {              // If the selected wasn't the last,
    
                var $next = $all.eq(index + 1)      // reference the next select
    
                $all.filter(':gt(' + index + ')').empty(); // and empty all selects greater than the 
                                                           // index of the changed one.
                                                           // This will include the one that is about
                                                           //     to be populated.
                    // Then presumably perform some AJAX
                    //    based on $th.val(); to populate
                    //    $next with options.
             }
        });         
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Something like this will disable all select boxes: $('select').attr('disabled', 'disabled');… May 15, 2026 at 7:02 pm
  • Editorial Team
    Editorial Team added an answer Dozer works well for this. Simply map the bean instance… May 15, 2026 at 7:02 pm
  • Editorial Team
    Editorial Team added an answer If you get a 0 for a response code, the… May 15, 2026 at 7:02 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

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.