I'm working in asp mvc c#
Now in my acp panel I have a dropdownlist:
@Html.DropDownList("id", new SelectList(ViewBag.DruhyOdznaku, "Id", "Name"), new {@onchange = "functionChange()", @class = "form-control", id = "ddlViewBy"})
I can access the name value of selected item from JS like:
function functionChange() {
var e = document.getElementById("ddlViewBy");
var finalData = e.options[e.selectedIndex];
}
Now the problem is I want to keep displaying name in the dropdown but obtain another value - in this case "Text" (from db).
How can I attach this data to the dropdown (ideally keep the way it's created) and then get them from js? Spent a day on this, my sanity going low.
Thanks a milion for help.