Skip to content Skip to sidebar Skip to footer

Getting Checkbox To Display If Certain Item Is Selected

On my Create.cshtml page I have a dropdownlist:
@Html.LabelFor(model => model.activityID, 'Assignment', htmlAttributes: new { @class = 'co

Solution 1:

You need to listen to the change event of the dropdown, get the selected value and hide/show the other form control.

The below code assumes you have jQuery loaded in your page.

$(function(){
   $("#chkbx").hide();   // hide initially on

   $("#activityID").change(function(){
      var selectedActivity = $(this).val();
      $("#chkbx").hide();
      if(selectedActivity==="SomethingYouExpect")
      {
        $("#chkbx").show();
      }
   });

});

Change SomethingYouExpect to your specific value you want to check against.

Post a Comment for "Getting Checkbox To Display If Certain Item Is Selected"