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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:46:07+00:00 2026-05-14T07:46:07+00:00

I have 2 dropdown lists on my webform and using jquery trying to filter/reset

  • 0

I have 2 dropdown lists on my webform and using jquery trying to filter/reset filter 2nd dropdown elements based on 1st dropdown selection.

$(document).ready(function()
{
       $('#dropdown1').change(function(e)
       {
            switch ($(this).val())
            {
                 case "4":
                 //this removal works
                 $('#dropdown2').filter(function()
                    {
                        return ($(this).val() == 16);

                    }).remove();
                    break;


                 .................    
                 default:
                 //how would I restore filter here? 

            }

       }

});

Removing part works, so it filters item with no problem, but I have difficulty restoring the filter on dropdown 2 if something else is chosen in dropdown 1. I was trying to use .hide() and .show() instead of .remove() but it doesn’t seem to work on IE6 at least.

  • 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-14T07:46:08+00:00Added an answer on May 14, 2026 at 7:46 am

    At the start of your document ready take a copy of the values in dropdown2 like this:

    var drp2values = $('#dropdown2').html();
    

    then whenever you want to reset the values in dropdown2 to its original state do this:

    $('#dropdown2').html(drp2values);
    

    The actual value in the var will be something like :

    <option value="11">11</option>
    <option value="12">12</option>
    <option value="13">13</option>
    <option value="16">16</option>
    

    just tried it:

    This code works:

    $(document).ready(function()
    {
    var drp2values = $('#dropdown2').html();
    
           $('#dropdown1').change(function(e)
           {
                switch ($(this).val())
                {
                     case "4":
                     //this removal works...  now ;)
                     $('#dropdown2').find('option').filter(function()
                        {
                        alert('in4 filt' + drp2values + $(this).val());
                            return ($(this).val() == 16);
    
                        }).remove();
                        break;  
                     default:
                     //how would I restore filter here? 
                     $('#dropdown2').html(drp2values);
                }
    
           });
    
    });
    

    With this HTML

    <BODY>
        <select id='dropdown1'>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
        </select>
    
        <select id='dropdown2'>
            <option value="11">11</option>
            <option value="12">12</option>
            <option value="13">13</option>
            <option value="16">16</option>
        </select>
    </BODY>
    

    The original code you posted where you said the remove worked, it didnt remove the individual option with value 16, it removed the entire dropdown as you were not geting the options before you filtered, you were removing the dropdown 🙂

    Hope this helps.

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

Sidebar

Related Questions

I have dropdown-Lists which have a lot of elements (>1000). When I select one
I have two dropdown lists containing customers info. Using PHP for loop, I have
I have 5 dropdown lists and am trying to make it so if I
I have this dropdown. I need clone for my other dropdown lists: <select name=general>
I have a 2 dropdown lists side by side. When user selects from the
In my online store I have a dropdown that lists a number of products.
Currently I have a web application where a user can use dropdown lists to
I have implenmented drop-down lists Select menus in jQuery Mobile. <div data-role=fieldcontain> <label for=name
I have the webform with dropdown list, label and textbox. Like below: <asp:DropDownList ID=ddlTest
I am trying to get value of selected item using JQuery in a radio

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.