Late,
How can I do to call the OnSelectionChanged event of a DDL using MVC?
I have the following DDL:
@Html.DropDownListFor(model => model.Type, ViewBag.Type as SelectList, "-- Select --", new { id = "ddlType", onchange = "onchange()" })
And based on the item selected in this DDL, I give a Hidden in another DDL, that is, this 2nd DDL will only be shown if a specific option of the 1st DDL is checked.
The 2nd DDL is this:
@Html.DropDownListFor(model => model.SimilarId, ViewBag.SimilarId as SelectList, "-- Select --", new { id = "ddlSimilarId" })
PS: I also wanted to do this for a RadioButton ..
Thank you in advance.
EDIT
This Bundle is already referenced in the "Master Page" _Layout .. @ Scripts.Render ("~ / bundles / jquery")
I did it that way, nothing happens, what is still missing?
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
<script type="text/javascript">
$(function onchange() {
if (document.getElementById("ddlType").value == "Eletronic") {
document.getElementById("ddlSimilarId").disabled = "disabled";
}
});
</script>
I've tried it too:
<script type="text/javascript">
$(function () {
$("#ddlType").change(function () {
if ($(this).val() == "Eletronic") {
$("#ddlSimilar").disabled = "disabled";
}
});
});
</script>