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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:29:23+00:00 2026-06-08T23:29:23+00:00

I have 2 select menus with matching options e.g <select id=select-one> <option value=1>1</option> <option

  • 0

I have 2 select menus with matching options e.g

<select id="select-one">
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
</select>

<select id="select-two">
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
</select>

What I need to do inside the change function is if an option is selected from either menu, hide/remove the matching option from the other list. I need to show it again when a different option is selected.

I hope that’s enough info but please ask if you need any more.

EDIT

Sorry I missed it out but I am using the chosen plugin

  • 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-06-08T23:29:24+00:00Added an answer on June 8, 2026 at 11:29 pm

    The first thing I’d personally do is add a data-* attribute to each of your selects, containing the ID of the other select. That allows you to make your code more generic, rather than having to mostly duplicate it with switched IDs:

    <select id="select-one" data-select="select-two">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
    </select>
    
    <select id="select-two" data-select="select-one">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
    </select>
    

    Then the jQuery code:

    $('#select-one,#select-two').chosen().change(function(e) {
        var that = this;
        var $otherSelect = $('#' + $(this).data('select'));
        $otherSelect.find('option').show().filter(function() {
           return this.value == that.value;
        }).hide();        
    });
    

    That adds a change event handler to the two selects. The first thing it does is store a copy of this (the <select> that was changed) into another variable, so it can refer to it inside the function passed to .filter().

    Then it gets a reference to the other <select> element, using the data-select attribute of the element.

    Now it selects all option elements inside that, and shows them, then filters that list down to just the one with the matching value, and hides that.

    UPDATE:

    If you’re calling the chosen plugin on the <select> elements individually, you may want to move the anonymous function to a named function, like so:

    function handleChange() {
        var that = this;
        var $otherSelect = $('#' + $(this).data('select'));
        $otherSelect.find('option').show().filter(function() {
            return this.value == that.value;
        }).hide();
    }
    

    Then pass a reference to that function when assigning your change event handlers individually:

    $('#select-one').chosen().change(handleChange);
    $('#select-two').chosen().change(handleChange);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my php file I have two select menus. When the first one is
I have two select menus (#id1 and #id2) that, when validated as containing a
i have a 2 types of select list menus: <select name=category> <option>----Select----</option> <option>Category 1</option>
I am outputing a simple list of options from dynamic select menus using Codeigniter/MYSQL.
I have a big form with 132 (12x11) select menus which are populated from
I need a javascript solution for the following situation: I have two select drop
I have 2 drop-down menus. User selects something from the first one, then the
I have two drop down menus, one of which I am trying to replace
I have 4 optgroup select menus that appear dependent on the value of the
I have implenmented drop-down lists Select menus in jQuery Mobile. <div data-role=fieldcontain> <label for=name

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.