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

Select a ComboBox Value from Jquery

1 Answer 420 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 17 Dec 2012, 01:22 PM
Hi,

I have a little issue, i'm explaining :

I'm working with Kendo and Google Map API and some data are retrieve from the API, like address, postal code, city, country, etc...
I would like to populate different ComboBoxes (Address combobox, Postal Code combobox, etc...)

The problem is that i don't know how to retrieve the selected value from a combobox, any idea please ?

Here is my code :

On Controller (which populate countries combobox) :

public JsonResult GetCascadeCountries()
{
   return Json(_db.Countries.Select(c => new {CountryId = c.Id, CountryName = c.CountryName }), JsonRequestBehavior.AllowGet);
}

Index.cshtml : 

 @(Html.Kendo().ComboBox()
           .Name("Countries")
           .Placeholder("Select a country")
           .DataTextField("CountryName")
           .DataValueField("CountryId")
           .DataSource(source => {
           	source.Read(read => {
                    read.Action("GetCascadeCountries""Index");
                });
           })
   )

In the javascript file :

if (elt.types[0] == 'country')
    {
        var countriesComboBox = $('#Countries').data("kendoComboBox");
        alert($('#Countries_input').data());
        var selectItem = function (dataItem) {
            //dataItem argument is a ComboBox data item.
            return dataItem.Text == elt.long_name;
        }
 
        countriesComboBox.select(selectItem);
    }

I tried with a document.getElementsByName ou document.getElementById, to set the value, but i still fail :/

Any idea ?

Thanks

Edit : I've found, you have to set the trigger manually : countriesComboBox.trigger("change");

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 19 Dec 2012, 08:33 AM
Hello Thomas,

Your approach to select value looks correct. Check this JSBin it selects the second item properly. 
To get the actual value you should use the value method.

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