javascript - Remove selected items in the previous selections after cloning into a new dynamically generated dropdownlist -


i have asp.net dropdown list , asp.net button control. each time on clicking button, new dropdownlist supposed generated values except 1 selected previously.

for example: if selected 'a' list of values {a,b,c} , clicked on button, supposed new dropdownlist values {b,c}.

although, able clone dropdownlist values, have no idea how filter values removing selected ones.

edit

here scenario

  • i start off 1 drop down list (that has 5 options) => 1,2,3,4,5 -> first options selected default.
  • i select option 5 (in select list #2)
  • i hit clone -> new list (#3) added options 2,3,4
  • i select option 2 (in select list #3)
  • i hit clone -> new list (#4) created options 3,4
  • ..and on.

here code:

<form id="form1" runat="server">     <div>         <asp:dropdownlist id="ddlcityname" runat="server" class="ddlclone" datatextfield="city" datavaluefield="city" cssclass=""></asp:dropdownlist>         <asp:button id="btnclone" runat="server" text="clone" />     </div>     <div id="container">     </div> </form> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript">     $(function () {         $("[id*=btnclone]").bind("click", function () {             var index = $("#container select").length + 1;             var ddl = $("[id$=ddlcityname]").clone();             ddl.attr("id", "ddlcityname_" + index);             ddl.attr("name", "ddlcityname_" + index);             $("#container").append(ddl);             $("#container").append("<br /><br />");             return false;         });     }); </script> 

you can selected value , remove new select after clone, this:

$(ddl).find("option[value='"+selval+"']").remove(); 

here jsfiddle running example: https://jsfiddle.net/ntvo173q/

i updated jsfiddle remove selected items, check out:

what did selected values , remove new select:

var ddl = $('#sel').clone();     $('select').each(function() {         $(ddl).find("option[value='"+$(this).val()+"']").remove();      }); 

https://jsfiddle.net/ntvo173q/1/


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -