multiselect dropdown based on other multiselect dropdown

别等时光非礼了梦想. 提交于 2021-01-29 05:16:39

问题


I am tryng to show/hide elements in a multiselect dropdown, based on the selection in another multiselect dropdown. Anyway, when I use the multiselect plugin I am not able to show/hide the elements. My code looks like this:

@Html.DropDownList("CompanyDropDown", new MultiSelectList(ViewBag.CompanyList,
         "COD_COMPANY", "DESCRIPTION", null), new
                {
                    multiple = "multiple",
                    @class = "multiselect",
                    onchange = "CompanyDropDownOnChange()"
                })


@Html.DropDownList("FlowDropDown", new MultiSelectList(ViewBag.ActiveFlow,
         "ID_FLOW", "DESCRIPTION", null), new
                {
                    multiple = "multiple",
                    @class = "multiselect",
                })

and the javascript part is here:

jQuery(function ($) {
    $("select").multiselect();
});   
function CompanyDropDownOnChange() {
    $("#FlowDropDown option[value=11]").css('display', 'none');
}

The sample should just hide the flow with id=11 in the second dropdown, when a company in the first dropdown is selected.


回答1:


I did some testing with a scenario like yours and found out that you were altering the wrong elements.

function CompanyDropDownOnChange() {
 $("input[name=multiselect_FlowDropDown][value=11]").closest('li').css('display', 'none');
}

Please, refer to this plunker for more details.



来源:https://stackoverflow.com/questions/38268501/multiselect-dropdown-based-on-other-multiselect-dropdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!