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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:42:20+00:00 2026-06-10T19:42:20+00:00

I have a 2 drop down lists with that same values and the values

  • 0

I have a 2 drop down lists with that same values and the values are populated by database values. The problem I am trying to solve is that the 2 drop down boxes cannot have the same value when the form is submitted. The POST values must be different.

If the user selects option A from dropdown box A, I would like to remove option A from drop downdrop box B. If the user then selects option B from dropdown box A, I would like option A to be put back in dropdown box B and the new value option B to be removed from dropdown box B.

I have tried a couple of different ways to do this, the closest being the following code.
This bit does what I want when the page loads…..

$(document).ready(function() {
    $.dropdownAcache = { 
        val : "",
        val1 : "",
    };

    $('#id_A').ready(function() {
        var optionval = $('#id_A').val();
        $.dropdownAcache.val = $('#id_A').val();
        $('#id_B > option[value=' + optionval + ']').remove();
    });

    $('#id_A').click(function() {
        var optionval = $('#id_A').val();
        $.dropdownAcache.val1 = $('#id_A').val();
        $('#id_B > option[value=' + optionval + ']').remove();
        $('#id_B').append$(dropdownAcache.val);
        $.dropdownAcache.val = $.dropdownAcache.val1;
    });

…. but all it seems to do is remove the values from dropdown box B but never adds the values back in. It’s actually quite comical as I end up with no values in dropdown box B, but in all seriousness can anyone help to get this working?

Cheers – Oli

  • 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-10T19:42:21+00:00Added an answer on June 10, 2026 at 7:42 pm

    The event you should be using is the ‘change’ event. Also, you don’t need the second .ready() callback, it serves no purpose (the first .ready() handles that)

    $.dropdownAcache = { 
        val : "",
        val1 : ""
    };
    
    $(document).ready(function() {
    
        var optionval = $('#id_A').val();
        $.dropdownAcache.val = $('#id_A').val();
        $('#id_B > option[value="' + optionval + '"]').remove();
    
        $('#id_A').change(function() {
            optionval = $('#id_A').val();
            $.dropdownAcache.val1 = optionval;
            $('#id_B > option[value="' + optionval + '"]').remove();
            $('#id_B').append( $.dropdownAcache.val );
            $.dropdownAcache.val = $.dropdownAcache.val1;
        });
    });
    

    (As for why your list never gets the values added back, you have an unfortunately placed typo .append$(dropdownAcache.val);)

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

Sidebar

Related Questions

Say I have a form that contains a drop-down list populated by values stored
I have a list of drop down lists populated form a database(using ASP.NET). These
I have a drop down list that is populated with data in the code
I have about 10 drop down list controls that get populated. Instead of copying/pasting
I have a page. That page is for registration. I have 3 drop-down boxes
I have a situation where I have multiple drop down lists that are hidden
I have five drop down lists with the same options in my form and
I have a drop down list that has options that need to be passed
I have a drop down list that triggers an updatepanel when the index is
I'm using classic asp, I have a drop down list that the user selects

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.