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

Assigning a variable from a selection

1 Answer 231 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
danielle
Top achievements
Rank 1
danielle asked on 29 Sep 2012, 03:14 PM
I have been trying all day to "catch" or assign/bind to the chosen state and assign it to a variable called "text" so that I can use it in yet another API call for the other drop down box "Products".
I figured I must just be missing something and was hoping for a little help. Thanks.


   <body>
            <div class="k-widget k-header">
                     <span class="infoHead">Information</span>
                     <p>
<input id="state" placeholder="Select State..." />
</p>
<p>
         <input id="products"/>
         </p>
            <script>

      $(document).ready(function() {
                    $("#state").kendoDropDownList({
                   //     optionLabel: "Select State...",
                        dataTextField: "name",
                        dataValueField: "abbreviation",
                        dataSource: {
                         transport: {
                              read: {
                                url: "http://openstates.org/api/v1/metadata/?apikey=????????",
                                dataType: "jsonp"
                              }
                            }
                        }

                    });
                        //  change: function(test){
                    //  var text = this.value()
            var states=$("#state").data("kendoDropDownList");
states.bind("change", function(e) {
    var text = (this.value())
                    alert (text)
});

          $("#products").kendoDropDownList({
                      optionLabel: "Select product...",
                        dataTextField: "legislature_name",
                        dataValueField: "legislature_name",
                        dataSource: {
                            transport: {
                              read: {
                                url: "http://openstates.org/api/v1/metadata/"+text+"/?apikey=???????????????????",
                                dataType: "jsonp"
                              }
                            }
                            }


                      })
                      $("#products").data("kendoDropDownList");
      });




            </script>


        </div>
   </body>

1 Answer, 1 is accepted

Sort by
0
Nohinn
Top achievements
Rank 1
answered on 02 Oct 2012, 09:04 AM
a) You could use the cascading dropdowns feature: http://demos.kendoui.com/web/dropdownlist/cascadingdropdownlist.html 
b) If solution a cannot be used then in the change callback of the state dropdownlist:
change: function() {
    var value = this.value();
    var cb = $('#products').data('kendoDropDownList');
    cb.dataSource.transport.options.read.data.PropertyToChange = value;
    cb.dataSource.read();
}

Tags
DropDownList
Asked by
danielle
Top achievements
Rank 1
Answers by
Nohinn
Top achievements
Rank 1
Share this question
or