Click here to Skip to main content
15,884,924 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What I want to do is , if in the multi select dropdown an option is selected it will be displayed in dropdown as it is a multi select drop down now if the option is selected and displayed it should be removed from the drop down list as it is already selected and once the selected option is removed and unselected it should be appended back again in the list.

What I have tried:

$('#ddlProductId').on('select2:select', function (e) {
        debugger
        var id = $("#ddlProductId").val().toString();
        var names = $("#ddlProductId").text().toString();
        var values = id.split(",");

/*        $("#ddlProductId option[value="+values[0]+"]").remove();*/
        var matchFloat = String(values).match(/[+-]?\d+(\.\d+)?/g);
        if (id == null || id == "" || id == undefined) {
            $("#PriceReferenceId").empty();
        }
        else {
            if (parseInt($("#BeatId").val()) > 0) {
                var action_list = document.getElementById("ddlProductId");
                var action_list2 = document.getElementById("ddlProductId");

                // Get selected items.
                var is_selected = [];
                for (var i = 0; i < action_list.options.length; ++i) {
                    is_selected[i] = action_list.options[i].selected;
                                 }
              
                 //Remove selected items.
                i = action_list.options.length;
                while (i--) {
                    debugger
                    if (is_selected[i] == true) {
                        action_list.remove(i);
                    }
                    
                }

                
                
                GetAllPriceReferenceId(id, "PriceReferenceId");
            }
Posted
Updated 8-Feb-22 0:54am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900