Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript Variable Scope with KendoUI Components
    primarykey
    data
    text
    <p>I am trying to capture the text from a Kendo AutoComplete component and save it to a variable to later use in other components. The code is below and I have a link to the code at <a href="http://jsbin.com/agopuz/10/edit" rel="nofollow">jsbin.com</a>. Note: the code jsbin.com does not work for me in IE9, Firefox and Chrome work fine.</p> <p>I attach my onSelect function fires when a selecton is made in the autoComplete control. I then assign the dataItem to my variable "selectedGeoname". I successfully write the object's text property to an element on screen and I use an alert to confirm that selectedGeoname is populated by the object.</p> <p>However, when I later try to use the variable to pass the value to another component, the variable is null. I instantiate both components and declare the variable inside $(document)ready. I would have to believe that this is all ablout scope so perhaps one of you javascript wizards can help poor old .Net guy to fix this code.</p> <p>Thanks,</p> <p>Greg</p> <pre><code>HTML as follows: &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;link href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.common.min.css" rel="stylesheet" type="text/css" /&gt; &lt;link href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.default.min.css" rel="stylesheet" type="text/css" /&gt; &lt;link href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.dataviz.min.css" rel="stylesheet" type="text/css" /&gt; &lt;link href="http://cdn.kendostatic.com/2012.2.710/styles/kendo.mobile.all.min.css" rel="stylesheet" type="text/css" /&gt; &lt;script src="http://code.jquery.com/jquery-1.7.2.min.js"&gt;&lt;/script&gt; &lt;script src="http://cdn.kendostatic.com/2012.2.710/js/kendo.all.min.js"&gt;&lt;/script&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt; &lt;label for="customer"&gt;Choose a customer:&lt;/label&gt; &lt;input id="customer" /&gt; &lt;div id="result"&gt;&lt;/div&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="stores"&gt;Choose a store:&lt;/label&gt; &lt;input id="stores" /&gt; &lt;/p&gt; &lt;script type="text/javascript"&gt; $(document).ready(function () { $("#customer").kendoAutoComplete({ dataTextField: "name", dataSource: { serverFiltering: true, transport: { read: { url: "http://ws.geonames.org/searchJSON", dataType: "json", data: { featureClass: "P", style: "full", maxRows: 12, name_startsWith: function () { return $("#customer").val(); } } } }, schema: { data: "geonames" } }, filter: "startswith", placeholder: "Select Customer...", height: 500, suggest: true, select: onSelect }); var selectedGeoname; function onSelect(e) { var dataItem = this.dataItem(e.item.index()); selectedGeoname = dataItem; //output $("#result").html(selectedGeoname.name); alert(selectedGeoname); } $("#stores").kendoDropDownList({ autoBind: false, enable: true, dataTextField: "StoreName", dataValueField: "StoreId", dataSource: { serverFiltering: true, transport: { read: { url: '@Url.Action("JsonGetStores", "Home")', data: { customer: selectedGeoname } } } } }); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload