4
Late,
How can I call the Onselecionchanged event from 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
That one Bundle is already referenced in the "Master Page" _Layout.. @Scripts.Render("~/Bundles/jquery")
I did it this 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 tried that way too:
<script type="text/javascript">
$(function () {
$("#ddlType").change(function () {
if ($(this).val() == "Eletronic") {
$("#ddlSimilar").disabled = "disabled";
}
});
});
</script>
Thanks for the help, I tried to use your code, but it didn’t work. I took a look at the link, and got to a function (it’s in the main topic), if you can, take a look, grateful.
– developer033
@developer033 I updated the answer.
– Leonel Sanches da Silva