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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:41:33+00:00 2026-05-22T23:41:33+00:00

I have first drop down list ddl1 which contains these values: Car Van and

  • 0

I have first drop down list ddl1 which contains these values:

  • Car
  • Van

and the second drop down list ddl2 contains:

  • Car Honda
  • Car BMW
  • Van Golf

I need a script that filters the second ddl for example when I choose Car, the second ddl should only show these two fields:

Car Honda
– Car BMW

My code:

<script type="text/javascript">
function Filter(){
    var names = $('#typeCar option').clone();
    $('#Type').change(function(){
        var val = $(this).val();
        $('#typeCar').empty();
        names.filter(function(idx, el){
            return val === 'ALL' || $(el).text().indexOf(val) >= 0;
        }).appendTo('#typeCar');
    });
}
</script>
  • 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-22T23:41:33+00:00Added an answer on May 22, 2026 at 11:41 pm

    you will want something like this:

    Each List Item value in the second list should start with the same value of the item in the first list. This is so it can be filtered by the value of the first.

    EDIT:

    Items in drop downs.

    List 1:

    Car     -Value = 001
    Truck   -Value = 002
    Van     -Value = 003
    

    List 2:

    Car option 1 - Value = 001001
    Car option 2 - Value = 001002
    Car option 3 - Value = 001003
    Truck   option 1 - Value = 002001
    Truck   option 2 - Value = 002002
    Truck   option 3 - Value = 002003
    Van     option 1 - Value = 003001
    Van     option 2 - Value = 003002
    Van     option 3 - Value = 003003
    

    Javascript:

    <script>
    
        //Array to hold original subTypes
        var _SubTypes = new Array();
    
        $(document).ready(
                          function()
                  {
                    //Store the sub types
                    StoreSubTypes();
    
                    //Set up company Type on Change
                    $("#comp_type").change(CompanyTypeOnChange);
                          }
                         );
    
        //Function to Store Initial List of Sub Types
        function StoreSubTypes()
        {
            $("#comp_subtype option").each(
                                   function(index, option)
                               {
                                //Store the option
                                _SubTypes[index] = option;
                               }
                              );
        }
    
        //Function to Filter Company Sub Types and Hide various fields
        function CompanyTypeOnChange()
        {
            //Filter the Sub TYpes
            FilterSubTypes();
        }
    
        //Filters the company sub types drop down
        function FilterSubTypes()
        {
            //Get the value of the selected Company Type
            var compType = $("#comp_type").val();
    
            //Remove all Sub Type Items
            $("#comp_subtype option").remove();
    
    
            //Add the related items back to the list
            $.each(_SubTypes, function(index, value)
                      {
                        //Get the current option
                        var option = _SubTypes[index];
    
                        //Get the first 3 characters of the value - this is the same as the compType if related
                        var subTypeIdentifier = option.value.substring(0,3);
    
                        //Add the option to the list if its valid for the compType
                        if(subTypeIdentifier==compType)
                        {       
                            $("#comp_subtype").append(option);
                        }
    
                        //Add the --None-- option
                        if (option.value=="")
                        {
                            $("#comp_subtype").append(option);
                        }
                      }
                      );
        }
    
    
        </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to populate a second drop down list (which contains counties) depending on
I have got 2 drop down list in my php form. Values in the
There will be two drop down lists, First have the list of mobile vendor,
I have two Drop Down Lists, the second ones are based off which one
I have a drop-down list with known values. What I'm trying to do is
I have a drop down list with two values (for now..) with other elements
I have two drop down list on a page. The first one list projects
Simple ASP.NET application. I have two drop-down controls. On the first-drop down I have
Please cosider this scenario: I have a form with 3 drop down list.I place
I have the following HTML containing a drop down list (single selection) <script type="text/javascript">

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.