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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:16:16+00:00 2026-05-30T17:16:16+00:00

I have two select with the same elements (options) in it. What I am

  • 0

I have two select with the same elements (options) in it.
What I am trying to do is that when the user select a value from the first select box, the second select box hides that option, and automatically select the first visible option if the selected option was the same as the one in the first select.

I know that :first selects the first element of a group of “objects”, and that :visible only select the “visible” ones, so i was thinking that using :first of :visible should work, but what I am getting is no selection at all.

if I remove the :visible it works unless the second select box has the first element selected, and the user selects the first element on the first select box

This is what I have so far, please keep in mind that I have tried :first and :visible in any combination, but I really think that the problem here is that “hide hasn’t finished its job when I use :visible

$('#style_position').change(function(){
    var sel_pos_id      = $(this).val();
    var sel_xtr_pos_id  = $('#style_position_extra').val();
    $('#style_position_extra option[value=' + sel_pos_id + ']').hide().siblings().show();
    if(sel_pos_id==sel_xtr_pos_id){
        $('#style_position_extra option')
            .removeAttr('selected')
            .filter(':visible')   //I also tried find(':visible')
            .filter(':first')     //I also tried find(':first')
                .attr('selected','selected');
    }
});
  • 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-30T17:16:17+00:00Added an answer on May 30, 2026 at 5:16 pm

    Here’s one method

    /* cache a set of options from second select*/
    var $opts=$('#style_position_extra option').clone();
    
    $('#style_position').change(function(){
        var sel_pos_id      = $(this).val();
        /* find matching option copy*/
        var $newOpts=$opts.filter(function(){
                return this.value !=sel_pos_id;                                             
        }).clone();
        /* replace exisiting options with match*/
        $('#style_position_extra').html( $newOpts);
    });
    

    Here’s another possibly simpler one

    $('#style_position').change(function(){
        var selected=$(this).find('option').not(':selected').clone();
        $('#style_position_extra').html(selected);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different elements with the same id . How do I select
I have two select elements. Making a choice on the first select will build
I have two select elements in my form, Category and Sub-category. At first, only
I have two select controls that I want to populate with the exact same
Lets say I have two subqueries: SELECT Id AS Id0 FROM Table0 => Id0
I have the following two columns: SELECT b.ip_address AS IP ,b.mask AS MASK FROM
I have two lists and I want to select items that are not in
I have the following two queries: select count(*) from segmentation_cycle_recipients scr , segmentation_instance si
I have two mysql queries: $sql = SELECT * FROM content WHERE threadName LIKE
I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name

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.