I have a page, bound to a model, with several dropdownlistfor controls. These work ok, however, some items on the form only need to be shown depending on the values of other fields. I can do this using the change event on the dropdownlist without a problem.
However, I also need this logic to fire, once the page is initially loaded, (as the page is an edit form as well as a new record form). Using the $(document).ready() function, when I try to read the value from the dropdownlist, I get an undefined or null reference error, as it seems the dropdownlist hasn't yet been bound to the data.
I also get this error using the $(window).load() function. How can I get the initial value of the dropdown list, once the page has loaded, so I can process the logic needed to show / hide the appropriate sections of the form?
The code I have is:-
var
dropdownlist = $(
"#Replacement"
).data(
"kendoDropDownList"
);
var
dataItem = dropdownlist.dataItem();
var
replacementVal = dataItem.Code;
if
(replacementVal==
'Y'
)
{
$(
'#divReplacementPost'
).show();
}
else
{
$(
'#divReplacementPost'
).hide();
}
Thanks