Reputation: 747
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))
Upvotes: 5
Views: 27209
Reputation: 21465
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
Upvotes: 11
Reputation: 343
var object= $("#typesCombo").data('kendoComboBox').dataItem() // For getting the selected object
Upvotes: 2
Reputation: 4766
You forget use # before id. Try following:
var selected = $("#typesCombo").data('kendoComboBox').value()
Upvotes: 11