Marius Vasile

Marius Vasile

  • 602
  • 1.9k
  • 143.1k

asp.net core javascript not working properly

May 3 2021 5:18 PM
I am trying to hide and unhide two divs based on ddl selected text. It works in one case but for the second it does not. I get the data corect but I don't know why is not working
 
View 
  1. <div class="col-md-1">  
  2.         <select id="AffCategory" class="form-control border-danger" asp-items="@Model.SelectAffectedCategory" asp-for="RiskAssessmentSecondary.AffectedCategory">  
  3.             <option value="">-- Select --</option>  
  4.         </select>  
  5.         <span asp-validation-for="RiskAssessmentSecondary.AffectedCategory" class="text-danger"></span>  
  6.     </div>  
  7.     <div id="ATRPeople" hidden class="col-md-1">  
  8.         <select class="form-control border-danger" asp-items="@Model.SelectJobList" asp-for="RiskAssessmentSecondary.AtRiskPeopleDetail">  
  9.             <option value="">--Select Job Title--</option>  
  10.         </select>  
  11.         <span asp-validation-for="RiskAssessmentSecondary.AtRiskPeopleDetail" class="text-danger"></span>  
  12.     </div>  
  13.     <div id="ATRAsset" hidden class="col-md-1">  
  14.         <select class="form-control border-danger" asp-items="@Model.SelectAssetList" asp-for="RiskAssessmentSecondary.AtRiskAssetDetail">  
  15.             <option value="">--Select Asset--</option>  
  16.         </select>  
  17.         <span asp-validation-for="RiskAssessmentSecondary.AtRiskAssetDetail" class="text-danger"></span>  
  18.     </div>  
 
 javascript
 
  1. $(function () {  
  2.             $("#AffCategory").on("change"function () {  
  3.                 var data = $("#AffCategory :selected").text();  
  4.                 debugger;  
  5.                 if (data == "People") {  
  6.                     $("#ATRPeople").attr("hidden"false);  
  7.                     $("#ATRLabel1").attr("hidden"false);  
  8.                     $("#ATRLabel2").attr("hidden"false);  
  9.                     $("#affc").val(data);  
  10.                 }  
  11.                 if (data == "Assets") {  
  12.                     $("#ATRAsset").attr("hidden"false);  
  13.                     $("#ATRLabel1").attr("hidden"false);  
  14.                     $("#ATRLabel2").attr("hidden"false);  
  15.                     $("#affc").val(data);  
  16.                 }  
  17.                 else {  
  18.                     $("#ATRPeople").attr("hidden"true);  
  19.                     $("#ATRAsset").attr("hidden"true);  
  20.                     $("#ATRLabel1").attr("hidden"true);  
  21.                     $("#ATRLabel2").attr("hidden"true);  
  22.                 }  
  23.             });  
  24.         });  
 
 
 

Answers (1)