Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when selecting from one of them to disable the others dropdowns note please to select the dropdowns by names not ID


What I have tried:

	$(function(){
    const branchChanged = function(){
        let branch = $("#branch").val();
        $("#warehouse").prop("disabled", branch !== "");
    };
    
    const warehouseChanged = function(){
        let warehouse = $("#warehouse").val();
        $("#branch").prop("disabled", warehouse !== "");
    });
    
    // Update the lists when a value is selected:
    $("#branch").change(branchChanged);
    $("#warehouse").change(warehouseChanged);
    
    // Handle the initial value, if any:
    branchChanged();
    warehouseChanged();
});
Posted
Updated 29-Mar-22 2:39am

1 solution

Simple enough:
JavaScript
$(function(){
    const lists = $("#branch, #warehouse");
    
    lists.change(function(){
        const value = this.value;
        lists.not(this).prop("disabled", value !== "");
    });
    
    const nonEmpty = lists.filter(function() { return this.value !== ""; }).eq(0);
    if (nonEmpty.length) {
        lists.not(nonEmpty).prop("disabled", true);
    }
});
If you want to change how you select the lists, then change the selectors in the const lists = ... line.
 
Share this answer
 

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