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

[Solved] How to get value of dropdownlist

4 Answers 301 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nim
Top achievements
Rank 1
Nim asked on 04 Jan 2011, 11:03 PM
Hello,

When I test the following code:

=====
<% Html.BeginForm("Save", "Home"); %>
<%= Html.Telerik().DropDownList()
    .Name("productID")
    .Items(item =>
    {
        item.Add().Text("Chai").Value("1").Selected(true);
        item.Add().Text("Chang").Value("2");
        item.Add().Text("Tofu").Value("3");
    })
%>
<% Html.EndForm(); %>
=====

it produces a drop-down with the names.  Yet, I am unable to:
 - get the value of the selected item in a Javascript (eg. document.getElementById('productID').value)

What I'm trying to do is:
 - when "Chang" is selected, I want to get the value "2" in a javascript. (...I don't see how I may get "Chang" either...)

What am I missing?  :-)

Thank you!

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 05 Jan 2011, 08:45 AM
Hi Nim,

 The Telerik DropDownList is not a <select> html element and that's why you cannot get's its value like this: document.getElementById('productID').value.

 I suggest you check the Client-side API help topic. In a word to get the value of the dropdownlist you must use:

var dropDownList = $('#productID').data('tDropDownList');
var value = dropDownList.value();

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ivan
Top achievements
Rank 1
answered on 07 Feb 2011, 07:32 PM
Hello
Using the Dropdownlist with duplicated texts (and different values) I noticed that obtaining the value of the second item I get the value of the first. Both items have the same text.

--
Ivan
0
Georgi Krustev
Telerik team
answered on 08 Feb 2011, 10:44 AM
Hello Ivan,

This is a known issue and it is already fixed. The fix will be included in the next official release of Telerik Components for ASP.NET MVC. The fix is also available for our commercial users as an internal build.

Best regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rick
Top achievements
Rank 1
answered on 20 Feb 2011, 09:15 PM
similar question - using autocomplete, where can I find information on the JSON data that needs to be created so taht both "value" and "text" are sent back to client?  All the telerik examples only send back "text" ?
Tags
ComboBox
Asked by
Nim
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ivan
Top achievements
Rank 1
Georgi Krustev
Telerik team
Rick
Top achievements
Rank 1
Share this question
or