I want to disable a field based on the selection from a dropdown list.

Here's my code so far:

<div class="form-group">
    @Html.LabelFor(x => x.ccVersandkostenTraeger, new { @class = "col-sm-2 control-label" })
    <div class="col-sm-5">
        @Html.DropDownListFor(x => x.ccVersandkostenTraeger, new SelectList(Model.ccVersandkostenTraeger), new { @class = "form-control versandkostentraeger" })
    </div>
</div>

<div class="form-group">
    @Html.LabelFor(x => x.ccKostenstelle, new { @class = "col-sm-2 control-label" })
    <div class="col-sm-5">
        @Html.TextBoxFor(x => x.ccKostenstelle, new { @class = "form-control kostenstelle" })
        @Html.ValidationMessageFor(x => x.ccKostenstelle)
    </div>
</div>

I tried this already:

    if ($(".versandkostentraeger").val() != "Absender") {
    $(".kostenstelle").attr("disabled", "true");
}

Basically the drop-down list versandkostentraeger only has two value to choose from: Empfänger or Absender.
I want kostenstelle to be disabled if Empfänger is selected or Absender is not selected(I write it like this because I don't know if the 'ä' can be read properly).
How can I achieve this?

Related posts

Recent Viewed