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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:20:58+00:00 2026-06-18T17:20:58+00:00

I have multiple dropdown menus with the same options. If one option was selected,

  • 0

I have multiple dropdown menus with the same options. If one option was selected, other dropdown menus will not show the selected option. When I tried to reset the selected option, it did not restore the removed select option.

HTML part:

<select id="selectNumber" class="selectbox">
    <option value="0">Choose a number</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
</select>
<select id="selectNumber2" class="selectbox">
    <option value="0">Choose a number</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
</select>

Javascript part:

$(".selectbox").change(function(){
    var selectedIndex = $(this).index();    
    var myVal = $(this).val();
    $(".selectbox").each(function(i){        
        if (selectedIndex != i){
            $("option", this).each(function(){                
               if (myVal == $(this).val() && myVal != 0){
                   $(this).detach();
               }else{
                   $(this).prepend();
                   //not work

               }

            });
        }
    });
});

the demo but not working

Thanks for your time.

  • 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-18T17:20:59+00:00Added an answer on June 18, 2026 at 5:20 pm

    This should do what you want

    /* store options */
    var $selects = $(".selectbox");
    var $opts = $selects.first().children().clone();
    
    
    $selects.change(function () {       
        var myVal = $(this).val();
        if (myVal !='0') {
             $selects.not(this).children('[value="'+myVal+'"]').remove();
        }else{
            var replaceVal=$(this).data('currVal');
            $selects.not(this).append( $opts.filter( '[value="'+replaceVal+'"]').clone())
        }
        $(this).data('currVal', myVal);
    
    });
    

    DEMO http://jsfiddle.net/7Ssu7/8/

    EDIT Version – keeps sort order

    /* store options */
    var $selects = $(".selectbox");
    var $opts = $selects.first().children().clone();
    
    
    $selects.change(function () {
        /*create array of all selected values*/    
        var selectedValues=$selects.map(function(){
            var val=$(this).val();
            return val !=0? val :null;
        }).get();
    
    
        $selects.not(this).each(function(){     
    
            var $sel=$(this), myVal=$sel.val() ||0;        
            var $options=$opts.clone().filter(function(i){
                var val=$(this).val();         
                return  val==myVal || $.inArray(val, selectedValues) ==-1;
            });
            $sel.html( $options).val( myVal)
        });  
    
    });
    

    DEMO: http://jsfiddle.net/8uunN/1/

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

Sidebar

Related Questions

I have a table that contains multiple dropdown menus for a list of profile
I have multiple dropdown list: @Html.DropDownListFor(x => x.HaveColoSpace.SelectedOptions, new SelectList(Model.HaveColoSpace.Options, Value, Text), new {
I have multiple UpdatePanels on a webpage, one inside UserControl (Purple ColorBox as show
I have to make a form with multiple drop-down menus that modify one another.
I have a form with multiple select dropdown menus that start with the id:
I have a mutliple drop down menus that I am using to hide/show rows
I have have this dropdown menu where you can select multiple values. Now let's
I have multiple drop down menus with my JSF/ICEFaces application that update each others
I have a drop down menu. By default it allows only one option to
Here's what I need to write for a bunch of dropdown menus: <select> <option

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.