Abdalla Omran

Abdalla Omran

  • NA
  • 334
  • 32.4k

Disable Select List options Once Chosen another select List

Mar 10 2021 1:24 PM
I have two selected list 
Branch and Warehouse 
if i choose value of one of them the onther should be disabled 
for example if i choosed a value from Branch then Warehouse should be disbaled and opposite is right . 
 
  1.   <div class="form-group">  
  2.                 <label asp-for="Input.Branch"></label>  
  3.                 <select asp-for="Input.Branch" id="branch" class="form-control">  
  4.                     <option value="">--Select Branch--</option>  
  5.                     @foreach (var item in Model.BranchesList)  
  6.                     {  
  7.                         <option value="@item.BranchId.ToString()">@item.BranchName</option>  
  8.                     }  
  9.                 </select>  
  10.   
  11.                 <span asp-validation-for="Input.Branch" class="text-danger"></span>  
  12.             </div>  
  13.   
  14.             <div class="form-group">  
  15.                 <label asp-for="Input.Warehouse"></label>  
  16.                 <select asp-for="Input.Warehouse" id="warehouse" class="form-control">  
  17.                     <option value="">--Select Branch--</option>  
  18.                     @foreach (var item in Model.WarehousesList)  
  19.                     {  
  20.                         <option value="@item.WareHouseId.ToString()">@item.Name</option>  
  21.                     }  
  22.                 </select>  
  23.                 <span asp-validation-for="Input.Warehouse" class="text-danger"></span>  
  24.             </div>  
  25.             <button type="submit" class="btn btn-primary">Register</button>  
  26.         </form>  
  27.   
  28. JavaScript :  
  29.  $(document).ready(function () {  
  30.             $("#branch").change(function () {  
  31.   
  32.                 if ($(this).val() == "branch") {  
  33.   
  34.                     $("#warehouse").attr('disabled', 'disabled');  
  35.                 }  
  36.                 else {  
  37.                     $("#warehouse").removeAttr('disabled');  
  38.                 }  
  39.             });  
  40.         });  
 
 
 
 
 

Answers (4)