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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:04:55+00:00 2026-05-20T03:04:55+00:00

I have a page that shows 3 drop-down selectors on the page. I also

  • 0

I have a page that shows 3 drop-down selectors on the page. I also have a jQuery code that checks to make sure that if one option is selected the same one is not allowed to be selected in the other 2 drop-downs.

I need to change the code not to only stop from allowing selecting a duplicate but to completely remove selected option from the other drop-downs below this one. I assume I would have to put all options into an array and somehow remove from the list when generating next drop-down.

Alternatively I need to mark already selected ones with a different color, with a class, perhaps.

Here’s my current code:

$('.mySelect').change(function(index, elem){
    var myFilter = $(this).val();
    if(myFilter !="selectOne"){
        var size = $('.qSelect').not(this).not(function(index){
        return $(this).val() != myFilter;
    }).size();
        if(size > 0){
            alert("already selected.");
        } else {
            // do something
        }   
    }   
});

<select name="select1" class="mySelect">
    <option value="selectOne">Select one</option>
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Option 3</option>
</select>

<select name="select2" class="mySelect">
    <option value="selectOne">Select one</option>
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Option 3</option>
</select>   

<select name="select3" class="mySelect">
    <option value="selectOne">Select one</option>
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Option 3</option>
</select>
  • 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-20T03:04:56+00:00Added an answer on May 20, 2026 at 3:04 am

    Rather than creating an array and removing/re-inserting items, you could use proper form field behaviour and set the option to ‘disabled’. It can be confusing to users if you remove elements.

    You could do this by going:

    $('.mySelect').bind('change', function(el) {
    
        var _this = $(this),
            newVal = _this.val();
        $('select.mySelect:not([name=' + _this.attr('name') + ']) 
                option[value=' + _this.data('oldVal') + ']').attr('disabled', false);
        $('select.mySelect:not([name=' + _this.attr('name') + ']) 
                option[value=' + newVal + ']').attr('disabled', true);
        _this.data('oldVal', newVal);
    
    });
    

    (http://jsfiddle.net/KT856/)

    You can change “.attr(‘disabled’, true)” to apply what ever treatment you decide.

    Also – I assume you’re validating this on the server-side as well 😉

    Edit: updated script so that it stores “previous selection” in order to reenable those options in the other selects if the selection changes.

    NB: this approach will work no matter which order the user selects options.

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

Sidebar

Related Questions

I have a simple drop down box on a page with the below code:
In my aspx page I have drop down list that initialy in page load
I have a select drop-down that selects a theme for the current page the
I have some drop-down boxes that act as filters on a page. When either
I have a page that has two drop down lists on it and a
I have a page that shows statistics for users, this cannot be cached because
I have a page ItemList that shows a list of items using div's. After
I have a Drupal 7 installation that shows the default front page. Published pages/nodes
I have this line below that shows a link to go the next page
I have a page that has fields dynamically loaded via JQuery. It allows a

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.