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

  • Home
  • SEARCH
  • 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 675445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:49:08+00:00 2026-05-14T00:49:08+00:00

I’m trying to re-append a removed option to the appropriate select option menu. I

  • 0

I’m trying to re-append a “removed option” to the appropriate select option menu.

I have three select boxes: “Categories”, “Variables”, and “Target”. “Categories” is a chained select, so when the user selects an option from it, the “Variables” select box is populated with options specific to the selected categories option. When the user chooses an option from the “Variables” select box, it’s appended to the “Target” select box. I have a “remove selected” feature so that if a user “removes” a selected element from the “Target” select box, it’s removed from “Target” and put back into the pool of “Variables” options. The problem I’m having is that it appends the option to the “Variables” items indiscriminately. That is, if the selected category is “Age” the “Variables” options all have a class of “age”. But, if the removed option is an “income” item, it will display in the “Age Variables” option list.

Here’s the HTML markup:

<select multiple="" id="categories" name="categories[]">
  <option class="category" value="income">income</option>
  <option class="category" value="gender">gender</option>
  <option class="category" value="age">age</option>
</select>

<select multiple="multiple" id="variables" name="variables[]">
  <option class="income" value="10">$90,000 - $99,999</option>
  <option class="income" value="11">$100,000 - $124,999</option>
  <option class="income" value="12">$125,000 - $149,999</option>
  <option class="income" value="13">Greater than $149,999</option>
  <option class="gender" value="14">Male</option>
  <option class="gender" value="15">Female</option>
  <option class="gender" value="16">Ungendered</option>
  <option class="age" value="17">Ages 18-24</option>
  <option class="age" value="18">Ages 25-34</option>
  <option class="age" value="19">Ages 35-44</option>
</select>

<select height="60" multiple="multiple" id="target" name="target[]">
</select>

And, here’s the js:

/* This determines what options are display in the "Variables" select box */
    var cat = $('#categories');
    var el = $('#variables');

    $('#categories option').click(function() {
        var class = $(this).val();
        $('#variables option').each(function() {
            if($(this).hasClass(class)) {
                $(this).show();
            } else {
               $(this).hide();
            }
        });
    });

/* This adds the option to the target select box if the user clicks "add" */
    $('#add').click(function() {  
        return !$('#variables option:selected').appendTo('#target');  
    });

/* This is the remove function in its current form, but doesn't append correctly */
    $('#remove').click(function() {
                $('#target option:selected').each(function() {
                        var class = $(this).attr('class');

                        if($('#variables option').hasClass(class)) {
                                $(this).appendTo('#variables');
                                sortList('variables');
                        }
                });
    });
  • 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-14T00:49:08+00:00Added an answer on May 14, 2026 at 12:49 am

    You will actually find you are headed down the wrong road as you cannot “hide” option elements consistently across browsers. You actually need to add and remove them to alter the list.

    I put together a working version of what you are looking for, and you can view it or edit it on JSBin.

    The basic flow is as follows:

    1. On page load, grab all the options from #variables and store then in a hash/array for later use.
    2. Create a update_variables function that empties the variables list, adds in all the correct ones for the selected category. The important part here, is it checks if target has the item with that value already and will not add it again as it is already added to target.
    3. On “Add” just append the selected elements from #variables to #target and deselect them.
    4. On “Remove” just remove the selected elements from #target and call update_variables()

    Here is a sampling of a few methods. Look at the source on JSBin for all the code needed:

    opts ends up looking like this:

    var opts = {
        'age':[
           { label: 'Ages 18-24', value: 17 },
           { label: 'Ages 25-34', value: 18 },
           { label: 'Ages 35-44', value: 19 }
        ]
        ....
    }
    

    Here is the update_variables function:

    function update_variables(){
       var cat = $cats.val(), new_opts = [];
       $vars.empty();
    
       $.each(opts[cat], function(){
         if( $target.find('[value=' + this.value + ']').length === 0 ){
           new_opts.push(option(this.value, this.label));
         }
       });
    
       $vars.html(new_opts.join(''));
    }
    

    Note: the option() function is a little helper that creates the HTML for an option element.

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

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.