1

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

Jecob Jr.
  • 29
  • 1
  • 6

2 Answers2

1

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()";
JamesS
  • 2,167
  • 1
  • 11
  • 29
1

You can use:

document.getElementById("JobType").addEventListener("change", myFunction);

function myFunction() {

}

or if you're using JQuery:

$("#JobType").change(function() {
});
SᴇM
  • 7,024
  • 3
  • 24
  • 41