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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:14:48+00:00 2026-06-16T20:14:48+00:00

Html <div id=opts class=styled-select> <select id=combo1 class=combo data-index=1> <option></option> <option val=Opt1>Opt1</option> <option val=Opt2>Opt2</option> <option

  • 0

Html

<div id="opts" class="styled-select">
 <select id="combo1" class="combo" data-index="1">
        <option></option>
        <option val="Opt1">Opt1</option>
        <option val="Opt2">Opt2</option>
        <option val="Opt3">Opt3</option>
    </select>
</div>



<div id="opts2" class="styled-select">
  <select id="combo2" class="combo2" data-index="1">
            <option></option>
            <option val="Opt11">Opt11</option>
            <option val="Opt22">Opt22</option>
            <option val="Opt32">Opt33</option>
        </select>
 </div>

jQuery

$('#opts').on('change', '.combo', function() {
    var selectedValue = $(this).val();

    if ($(this).find('option').size() > 2) {
        var newComboBox = $(this).clone();
        var thisComboBoxIndex = parseInt($(this).attr('data-index'), 10);
        var newComboBoxIndex = thisComboBoxIndex + 1;

        $('.parentCombo' + thisComboBoxIndex).remove();

        if (selectedValue !== '') {
            newComboBox.attr('data-index', newComboBoxIndex);
            newComboBox.attr('id', 'combo' + newComboBoxIndex);
            newComboBox.addClass('parentCombo' + thisComboBoxIndex);
            newComboBox.find('option[val="' + selectedValue + '"]').remove();
            $('#opts').append(newComboBox);
        }
    }
});​

I can’t duplicate/use the same code for 2 different comboboxes, it seems to cause some kind of trouble.

How can I have the same “effect” for 2 comboboxes?

Cheers.

  • 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-16T20:14:49+00:00Added an answer on June 16, 2026 at 8:14 pm

    Cloning elements also clone its properties and I have made some changes in your code! check them and see what i have changed 🙂 I wrapped them in a div and some more things!

    Jquery:

    $('body').on('change', '.combo', function() {
        var selectedValue = $(this).val();
    
        if ($(this).find('option').size() > 2) {
            var newComboBox = $(this).clone();
            var thisComboBoxIndex = $(this).attr('id').replace("combo", "");
            var newComboBoxIndex = thisComboBoxIndex + 10;
    
            $('.parentCombo' + thisComboBoxIndex).remove();
    
            if (selectedValue != '') {
                newComboBox.attr('data-index', newComboBoxIndex);
                newComboBox.attr('id', 'combo' + thisComboBoxIndex);
                newComboBox.find('option[val="' + selectedValue + '"]').remove();
                $('div.'+thisComboBoxIndex).append(newComboBox);
            }
        } 
    });​
    

    HTML:

        <div class="1">
        <select id="combo1" class="combo" data-index="1">
            <option></option>
            <option val="Opt1">Opt1</option>
            <option val="Opt2">Opt2</option>
            <option val="Opt3">Opt3</option>
        </select>
    </div>
    <br>
    <div class="2">
        <select id="combo2" class="combo" data-index="2">
            <option></option>
            <option val="Opt1">Opt1</option>
            <option val="Opt2">Opt2</option>
            <option val="Opt3">Opt3</option>
        </select>
    </div>
    

    ​
    Working Fiddle

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

Sidebar

Related Questions

I have this html div tag defined: <div style=height:100px; width:100px class=total-title> first text </div>
I have widgets/portlets similar to <div id=100 class=portlets> <iframe src=widgets/widget1_iframe.html></iframe> </div> Within each iFrame
I've an html div like <div class=main-div font-color page-padding> <div> <table> <tbody> <tr> <td
I have an html div element, which contains lot of HTML-5 data- attributes to
I have html div class formated accordingly.... <div class=latest-media-images> <div class=hdr-article>LATEST IMAGES</div> <a class=lnk-thumb
I have a HTML DIV element: <div class=obj height=this is attr 1 rel=this is
I am trying to generate an html div in asp.net. Since a div is
I want to add row with remove button through javascript in html div formate.
What is the best way to set the transparency of a HTML DIV element
I have created a simple layout using the HTML div tag. I would like

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.