On MVC3, with a dropdownlist defined as
@Html.dropDownList(m=>m.model, new SelectList(m.myList, "value", "text"))
How can I get the selected value and/or text via javascript?
I tried passing a name:
@Html.dropDownList(m=>m.model, new SelectList(m.myList, "value", "text"), new {name="name")
and reading the name from the javascript:
document.getElementByName(“name”)
but that does not work.
If you are using jQuery (which is highly likely with an MVC project):
Of course, you could combine this into a single line if desired.
If you aren’t using jQuery, see https://stackoverflow.com/a/1085810/453277.
Manual ID: