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

Cant get the value

1 Answer 429 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 27 Jun 2012, 09:15 AM
Hey I've been trying to get the value from a dropdownlist, and cant seem to get it working. Am I doing something wrong.
The dropdown displays normally and everything and i map the event fine, but once it fires i get this javascript error when it tries to get the value:

 "Uncaught TypeError: Cannot call method 'value' of undefined" Here is my code:

                @Html.LabelFor(m => m.Country)
                @(Html.Kendo().DropDownListFor(m => m.Country)
                  .Name("CountriesDropDown")
                  .DataTextField("Name")
                  .DataValueField("CountryID")
                  .DataSource(source =>
                  {
                    source.Read(read =>
                    {
                        read.Url("/WebUI/API/Countries/");
                     });
                   })
                  .Events(e => e.Change("CountryChange"))
                  )  

<script type="text/javascript">

    var CountriesList = $("#CountriesDropDown").data("kendoDropDownList");

    function CountryChange() 
    {
        alert(CountriesList.value());
    }
    
</script>

Thanks in advance!

UPDATE:

I noticed one more strange thing, I use DropDownListFor to map the dropdown list to my model. On the server side, if I have a Name for this DropDownList defined ( .Name("CountriesDropDown") ) i doesnt catch the value of the dropdown list if I remove the name it works fine. Is this a bug, or am I missing something?




1 Answer, 1 is accepted

Sort by
0
Dennis
Top achievements
Rank 1
answered on 27 Jun 2012, 08:36 PM
I got past this using it like this:

$("#CountriesDropDown").data("kendoDropDownList").value();
Tags
DropDownList
Asked by
Dennis
Top achievements
Rank 1
Answers by
Dennis
Top achievements
Rank 1
Share this question
or