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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:43:27+00:00 2026-05-17T20:43:27+00:00

I am working on a project where I have a form that will have

  • 0

I am working on a project where I have a form that will have multiple ‘select’ inputs, all with the same set of options. I would like to use jquery to disable/hide an option in the rest of the ‘select’ inputs, if it has already been selected.

For example:

<select id="1">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
</select>

<select id="2">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
</select>

The user chooses ‘Volvo’ on the first select. I would like it removed from the second select.

Any info would be greatly appreciated.

  • 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-17T20:43:27+00:00Added an answer on May 17, 2026 at 8:43 pm

    Here there is the code to continue selecting and disabling all the times we want.

    First thing is to enable every option, and then look at the selected values, and disable the options which coincides with the selected values.

    These 2 steps are crucial because if you select again, the disabled values of before would continue disabled.

    NEWEST VERSION

    The more elegant way, where we use map() (in stackoverflow there is a good explanation about this method) and filter() jquery functions to do the job. Less lines, and I think same performance or better.

    http://www.jsfiddle.net/dactivo/keDDr/

    $("select").change(function()
     {
    
            $("select option").attr("disabled",""); //enable everything
    
         //collect the values from selected;
         var  arr = $.map
         (
            $("select option:selected"), function(n)
             {
                  return n.value;
              }
          );
    
        //disable elements
        $("select option").filter(function()
        {
    
            return $.inArray($(this).val(),arr)>-1; //if value is in the array of selected values
         }).attr("disabled","disabled");   
    
    });
    

    NEW VERSION

    I have edited my answer, this is my final version:

    http://www.jsfiddle.net/dactivo/kNbWc/

    $("select").change(function()
                       {
    
            $("select option").attr("disabled",""); //enable everything
            DisableOptions(); //disable selected values
    
                       });
    
    
    function DisableOptions()
    {
        var arr=[];
          $("select option:selected").each(function()
                  {
                      arr.push($(this).val());
                  });
    
        $("select option").filter(function()
            {
    
                  return $.inArray($(this).val(),arr)>-1;
       }).attr("disabled","disabled");   
    
    }
    

    OLD VERSION

    http://www.jsfiddle.net/AyxL3/

    $("select").change(function()
                       {
    
            $("select option").attr("disabled",""); //enable everything
            DisableOptions(); //disable selected values
    
                       });
    
    
    function DisableOptions()
    {
    
        $("select option").filter(function()
            {
                  var bSuccess=false; //will be our flag to know it coincides with selected value
                  var selectedEl=$(this);
                  $("select option:selected").each(function()
                  {
    
                      if($(this).val()==selectedEl.val())
                      {
                           bSuccess=true; //it coincides we will return true;
                           return false; // this serves to break the each loop
                       }               
    
                  });
                  return bSuccess;
       }).attr("disabled","disabled");   
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started working on a project that will involve multiple people entering data
I have project that I'm working on that is going to require a webserver.
I'm working on a project where I have 2 web services that need the
I am working a project that does not have a trunk / branches /
One long term project I have is working through all the exercises of SICP.
I have a project that I'm working on and I need to be able
In my Zend Framework project, I have a form that I am testing. In
I have this project i'm working on and id like to add a really
On a recent project I have been working on in C#/ASP.NET I have some
I'm working on a project were we have number (5 at the moment) of

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.