Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how i get select value from kendo comboBox

i have implented Kendo ComboBox but struggling to get selected value ....

  $("#_FeeScheme_Input").kendoComboBox({
        minLength: 1,
        filter: 'contains',
        dataTextField: "FeeSchemeDescription",
        dataValueField: "FeeSchemeID",
        select: onSelect,
        dataSource: {
            type: "json",
            serverFiltering: false,
            transport: {
                read: "/Qualification/GetAllFeeScheme_JSON"
            },
        }
    });

...

 function onSelect(e) {

        var dataItem = this.dataItem(e.item.index());

        alert("value " + dataItem.text); //NOT WORKING... RETURN NULL VALUE            

    };

Razor code

 <div class="form-group">
                @Html.LabelFor(model => model._FeeScheme.FeeSchemeDescription, new { @class = "control-label col-md-3" })
                <div class="col-md-6">
                    @Html.TextBoxFor(model => model._FeeScheme.FeeSchemeDescription, new { id = "_FeeScheme_Input" })
                    @Html.ValidationMessageFor(model => model._FeeScheme.FeeSchemeDescription)
                </div>
 </div>
like image 427
K.Z Avatar asked Feb 20 '14 12:02

K.Z


People also ask

How to get selected value in kendo ComboBox?

load("@Url. Action("Load", "Home")" + id); var selected = $('#typesCombo'). data('kendoComboBox'). val(); if (selected == '') { ... }

How do I set default value in kendo ComboBox?

The selection can be set programmatically by calling the select() method on the widget instance. The following for example will set the selection to 'Thing1'. Finally, if you are using MVVM with declarative initialization, you can bind the selection to a value on a View Model.

What is Kendo ComboBox?

The Kendo UI for Angular ComboBox is a form component that lets you choose from a list of options. It is a richer version of the <select> element and supports data binding, filtering, templates, and the entering of custom values.


5 Answers

var c = $('#MyCombo');

// to get selected id
c.val() // and also
c.data('kendoComboBox').value()

// to get selected text
c.data('kendoComboBox').text()

// to get selected item index
c.data('kendoComboBox').select()

// to set selected item e.g. 3
c.data('kendoComboBox').select(2)
like image 93
Zolfaghari Avatar answered Oct 16 '22 07:10

Zolfaghari


The getters/setters from the kendo comboBox are part of the kendoComboBox 'class'.

You can use this.value() or this.text() depending on what you need.

$("#_FeeScheme_Input").kendoComboBox({
    minLength: 1,
    filter: 'contains',
    dataTextField: "FeeSchemeDescription",
    dataValueField: "FeeSchemeID",        
    dataSource: {
        type: "json",
        serverFiltering: false,
        transport: {
            read: "/Qualification/GetAllFeeScheme_JSON"
        },
    },
    change: function(){
       alert("value " + this.value());
    }
});
like image 31
Adrian Salazar Avatar answered Oct 16 '22 07:10

Adrian Salazar


You can use jquery too, If you try to take value out of events.

var CB= $("#_FeeScheme_Input").data("kendoComboBox");
var description= CB.dataItem(CB.select()).FeeSchemeDescription;   // for text field
alert(description);


var CB= $("#_FeeScheme_Input").data("kendoComboBox");
var Id= CB.dataItem(CB.select()).FeeSchemeID;   // for value field
alert(Id);
like image 33
MustafaP Avatar answered Oct 16 '22 07:10

MustafaP


This answer might help

Kendo combobox.value(x) not working correctly

And

Fiddle Example from the same answer

like image 37
Vivek Parekh Avatar answered Oct 16 '22 08:10

Vivek Parekh


You can also use jquery to get the ID and value like so:

First off give your comboBox a name:

$("#_FeeScheme_Input").kendoComboBox({
    Name: 'MyComboBox',
    minLength: 1,
    ...

Then you can get the ID and Value like this:

var myId = $("#MyComboBox").val();
var myText = $("#MyComboBox").data('kendoComboBox').text();
like image 23
Paul Gorbas Avatar answered Oct 16 '22 07:10

Paul Gorbas