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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:57:44+00:00 2026-06-15T09:57:44+00:00

I am trying to exclude from one select list what the user has chosen

  • 0

I am trying to exclude from one select list what the user has chosen in the other select list.

It is a list of 2 questions and the user can not select the same question in both select lists

For some reason it works for the first couple of selections but then it start altering the value of the second box to a value it was not. It works fine for a couple of selections on both but if you keep selecting between the 2 it start to return incorrect results

Below is the jquery code but here is the Link to Fiddle to complete code

var q1 = "#q1";
var q2 = "#q2";
var questions = {"1":"Question 1","2":"Question 2","3":"Question 3","4":"Question 4"}

function rebuildList(option,id) {
    var currentValue = $(id).val();
    $(id).empty();
    $(id).append($('<option></option>').val(0).html("Select"));

    $.each(questions, function (key, value) {
        if (key != option) {
            $(id).append($('<option></option>').val(key).html(value));
        }
    });

    //set the value back to what it was before emptying the list
    var setter;
    if (currentValue == "") {
        setter = id + " option:eq(0)";
    } else {
        setter = id + " option:eq(" + currentValue + ")";
    }


    $(setter).prop('selected', 'selected');
}



$(document).ready(function () {
    $(q1).change(function () {
        rebuildList($(this).val(), q2);  
        return false;
    });

    $(q2).change(function () {
        rebuildList($(this).val(), q1);  
        return false;
    });
});
  • 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-15T09:57:45+00:00Added an answer on June 15, 2026 at 9:57 am

    The problem happens when you use eq(). I modifed that part and the code works fine,

    if (currentValue == "") {
        $(id).val(0)
    } else {
        $(id).val(currentValue)
    }
    

    Check here, http://jsfiddle.net/muthkum/BsHHz/3/

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

Sidebar

Related Questions

I am trying to exclude more than one ID from a select list that
I'm trying convert xml from one format to other using the XslCompiledTransform in c#.
I'm trying to select all dom elements that have id=mydiv but exclude the ones
I'm trying to create an app where all data belongs to exactly one user,
I am tring update a record and want to exclude one column from the
I'm trying to exclude something from my results. I'm joining 3 tables, 1 with
I'm trying to learn some scripting however I can't find solution for one functionality.
I'm trying to create a list of files from a directory containing files with
I am trying to retrieve a value from a drop down list in MVC,
I'm trying to exclude from the build process an entire folder in eclipse but

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.