I have a C# web application that uses Razor views and Kendo UI web controls. On my form, I have a DropDownList defined like so:
@(Html.Kendo().DropDownListFor(m => m.MentalStatus).HtmlAttributes(new { id = "cmbMentalStatus", @class = "k-dropdown-width-30", @tabIndex = "1", style = "width:60px", onchange = "OnChangeC0100(cmbMentalStatus);" }).BindTo(ViewBag.ZeroToOne).OptionLabel(" "))
The onchange
property refers to this JS method:
function OnChangeC0100(cmb)
{
var stupidJS = document.getElementById("cmbV14_Adm_C0200_RepetitionThreeWords_Tab6");
stupidJS.disabled = (cmb.options[cmb.selectedIndex].value == "0");
}
When the second line tries to execute, I get this error
"Cannot read property 'undefined' of undefined"
What am I doing incorrectly? If I set a breakpoint, cmb
is not null
. stupidJS
is not null
.
Per this link, disabled
is the property to set. Is that not accurate?
Edit: I've looked at these questions:
How to Get Dropdown's Selected Item's text in Kendo UI?
how to get selected value for Kendo DropDownList
http://www.telerik.com/forums/dropdownlist-getting-clientside-value-on-selected-item-in-mvc
and the documentation here; http://demos.telerik.com/kendo-ui/dropdownlist/api
But no matter what I try in the Watch window, I can't get it to work:
That first one is the closest; at least it returns a value, but it's not the correct one. I selected the item whose text and value are both "1", yet it gives an empty string. Not shown in the screenshot, but $("#cmb").kendoDropDownList().val()
gives undefined
. Why is that if I hardcode a reference to the control, it sort-of works, yet the object passed as a parameter to the method doesn't work?