How can I get from kendo combobox value? I always getting undefined on it.. I've used these variants, but they are not worked for me
var selected = $('#typesCombo').data('kendoComboBox').val();
var selected = $('#typesCombo').data('kendoComboBox').value();
var selected = $('#typesCombo').data('kendoComboBox');
And getting error like: Cannot read property 'val' of undefined
Here's my code:
JS:
$('#loadContainer').load("@Url.Action("Load", "Home")" + id);
var selected = $('#typesCombo').data('kendoComboBox').val();
if (selected == '') {
...
}
HTML:
@(Html.Kendo().ComboBoxFor(x => x.Types.Name).Name("typesCombo")
.DataTextField("Name")
.DataValueField("Id")
.HtmlAttributes(new { style = "width:100%", id = "typesCombo" })
.BindTo(Model.TypesList))
There are many ways to get the widget selected value. If you are trying to get the value after it initialization and it has no selected value(declared in the index
parameter) you will get an empty value. If you want to get the value when user changes it, you can use the select
event and get the value like this:
$("#typesCombo").data('kendoComboBox').value(); // The selected value itself
$("#typesCombo").data('kendoComboBox').dataItem(); // The selected entire dataItem object
$("#typesCombo").val(); // Only if the target element is an input element
Working demo
You forget use # before id. Try following:
var selected = $("#typesCombo").data('kendoComboBox').value()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With