This is a migrated thread and some comments may be shown as answers.

getting the selected item

1 Answer 1287 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 29 Jul 2013, 12:07 PM
Hello,
I've started playing with kendo and I got a problem with getting the data on the eventchanged... my code is

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <input id="comboBox" />
   
    <script>
        $(document).ready(function () {
            $("#comboBox").kendoComboBox({
                dataTextField: "text",
                dataValueField: "value",
                dataSource: [
                    { text: "Item1", value: "1" },
                    { text: "Item2", value: "2" }
                ],
                change: function (e) {
                    var combobox = $("#comboBox").data("kendoComboBox");
                      var selectedIndex = combobox.select();
                    alert(combobox.select().text);
                }
            });
        });

    </script>
</asp:Content>

How do I get the object I've selected? for now it's as imple text/value what if it's an object of type

text, value, additionalinfo?

Thanks

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 30 Jul 2013, 11:01 AM
Hi Paolo,


You could use the dataItem method of the ComboBox to get the model for the selected item. As a side note, the context of the event handler is the ComboBox and it is accessible via this.
E.g.
function change(e) {
    var text = this.text();
    var value = this.value();
    var object = this.dataItem(this.select());
}

I hope that this information was helpful for you. I wish you a great day!

 

Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
ComboBox
Asked by
Michele
Top achievements
Rank 2
Answers by
Dimiter Madjarov
Telerik team
Share this question
or