get the value from input kendo ComboBox using JQuery

Toxic picture Toxic · Apr 1, 2014 · Viewed 14.7k times · Source

I am using kendo comboBox in my app and I need to get value and ID of record out of ComboBox, outside the ComboBox actual function.... I am using comboBox dropdown in table against each record so I can't relay on css ID to get comboBox value... I have managed to reach to input comboBox of selected record and I did this test by apply background color to it. I have tested .val() which works fine for just input textbox but its not happening for kendo ComboBox...

Many Thanks

input

  <td class="N_td">@Html.TextBox("Input_MarkingSchemeTitle_Element", null, new { id = @item.ElementID + "_EMST", @class = "ElementMarkingSchemeTitle k1-grid-input k-textbox_3 _MarkSchemeId_Input" })  </td>

ComboBox function

 $("._MarkSchemeId_Input").kendoComboBox({
        minLength: 1,
        filter: 'contains',
        dataTextField: "Name",
        dataValueField: "ID",
        dataSource: {
            type: "json",
            serverFiltering: false,
            transport: {
                read: "/Qualification/GetAllMarkScheme_JSON"
            },
        },
        change: function () {

           alert("value " + this.value() + "   " + this.text());                      
        }
    });

jQuery function

$("#ElementTable").on("click", ".k1-grid-confirm", function () {


   $(this).closest('table').find("._MarkSchemeId_Input").css("background", "red");

   var a1 = $(this).closest('table').find("._MarkSchemeId_Input").text(); // doesn't work

        alert("a1  " + a1);
 .....

Answer

Vojtiik picture Vojtiik · Apr 1, 2014

Have a look at the Kendo demo, it actually shows precisely what are you interested in

 var fabric = $("#fabric").data("kendoComboBox");
                var select = $("#size").data("kendoComboBox");
                $("#get").click(function() {
                    alert('Thank you! Your Choice is:\n\nFabric ID: ' +   fabric.value() + ' and Size: ' + select.value());
                });

The value retrieval in your example is not working because you are calling method at the html element not a Kendo control. Consider this example :

$("#combobox").kendoComboBox({
  dataSource: [ "Apples", "Oranges" ]
});
var combobox = $("#combobox").data("kendoComboBox");
combobox.value("Oranges");

Therefore in your case do following :

$(this).closest('table').find("._MarkSchemeId_Input").data("kendoComboBox").text()