Reputation: 29
how to use onchange event for @Html.DropDownListFor
@Html.DropDownListFor(model => Tlitem.JobType, (SelectList)newSelectList, new { @class = "form-control js-select js-noFilter hidden", size = "2", @value = 0, Id = "JobType" + t ,@onchange="alert('hello');"});
above code doesn't work
Upvotes: 1
Views: 9253
Reputation: 7213
You can use:
document.getElementById("JobType").addEventListener("change", myFunction);
function myFunction() {
}
or if you're using JQuery:
$("#JobType").change(function() {
});
Upvotes: 1
Reputation: 2300
Where onclick
is, just change that to onChange="javascript://whatever function you want()"
for example
@Html.DropDownListFor(model => Tlitem.JobType, (SelectList)newSelectList, new { @class = "form-control js-select js-noFilter hidden", size = "2", @value = 0, Id = "JobType" + t ,@onchange="javascript:onChangeFunction()";
Upvotes: 1