I have three DropDownLists. If a specific Value from my first DropDownList is chosen, the second Dropdownlist should be enabled. Example, if “Player 3” has been choosen, the other two DropDownList should be enabled, though, if “Player 2” is chosen the last DropDownList should be disabled and the second one enabled.
How can I easily do this? I am using MVC 3 EF model first.
This is my code in my view:
<p>Player</p>
<div class="editor-field">
@Html.DropDownListFor(m => m.PlayerName,Model.SubjectTypes, "Choose player" , new { @class = "selectstyle" })
@Html.ValidationMessageFor(model => model.PlayerName)
</div>
<p>Position</p>
<div class="editor-field">
@Html.DropDownListFor(model => model.PositionName, Model.Consultants, "Choose Position", new { @class = "selectstyle" })
@Html.ValidationMessageFor(model => model.ContactPerson)
</div>
<p>Team</p>
<div class="editor-field">
@Html.DropDownListFor(model => model.TeamName, Model.Teams, "Choose Team", new { @class = "selectstyle" })
@Html.ValidationMessageFor(model => model.ContactPerson)
</div>
You could subscribe to the
.change()event of the first dropdown and then based on the currently selected value enable/disable the others: