Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用multiselect select2下拉列表验证_Javascript_Php_Jquery_Yii2_Jquery Select2 - Fatal编程技术网

Javascript 使用multiselect select2下拉列表验证

Javascript 使用multiselect select2下拉列表验证,javascript,php,jquery,yii2,jquery-select2,Javascript,Php,Jquery,Yii2,Jquery Select2,如果在DropDown1中选择了一个选项而无法在DropDown2中选择,则必须在此处选择multiselect下拉验证 $("#DropDown2").change(function() { var selected = $('#DropDown1').select2("val"); var NotDropDown1Val = $('#DropDown2').val()

如果在DropDown1中选择了一个选项而无法在DropDown2中选择,则必须在此处选择multiselect下拉验证

   $("#DropDown2").change(function()
        {   
            var selected = $('#DropDown1').select2("val");
    
            var NotDropDown1Val = $('#DropDown2').val();
            
            if(selected.length > 0)
            {
                if(NotDropDown1Val.length > 0)
                {
                    for (var i = 0; i <= NotDropDown1Val.length-1; i++)
                    {
                        if(selected.includes(NotDropDown1Val[i]))
                        {
                            alert('Applicable and Not Applicable can not same.');
                            var selectedStates = $("#DropDown2").select2("val"),
                            index = selectedStates.indexOf(NotDropDown1Val[i]);
                            
                            if (index > -1 )
                            {
                                // if NV is found, remove it from the array
                                selectedStates.splice(index, 1);
                                // and set the value of the select to the rest of the selections
                                $("#DropDown2").select2("val", selectedStates);
                            }
                            // alert(index); 
                            return false;                    
    
                        }
                    }
                }
                
            }
                
        });
    
        $("#DropDown1").change(function()
        {   
            
            var selected = $('#DropDown2').select2("val");
    
            var DropDown1SelectVal = $('#DropDown1').val();
            
            if(selected.length > 0)
            {
                if(DropDown1SelectVal.length > 0)
                {
                    for (var i = 0; i <= DropDown1SelectVal.length-1; i++)
                    {
                        if(selected.includes(DropDown1SelectVal[i]))
                        {
                            alert('Applicable and Not Applicable can not same.');
                            var selectedStates = $("#DropDown1").select2("val"),
                            index = selectedStates.indexOf(DropDown1SelectVal[i]);
                            
                            if (index > -1 )
                            {
                                // if NV is found, remove it from the array
                                selectedStates.splice(index, 1);
                                // and set the value of the select to the rest of the selections
                                $("#Promotion_MerID").select2("val", selectedStates);
                            }
                            // alert(index); 
                            return false;                    
    
                        }
                    }
                }
                
            }
            
        });