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

How to get text and value of certain DropDown item (not the selected item)?

2 Answers 640 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.
Poqwe
Top achievements
Rank 1
Poqwe asked on 10 Jan 2012, 01:00 PM
I need to get the value of the last dropdown item. How can I achieve this?
I managed to get the items in my OnOpen client event:
var items = $(this).data("tDropDownList").dropDown.$items;

After that I know I can reference the last item  and change the class like
items[items.length-1].className += " myClass";

But how can I get the items text or value?
What are the elements called that the actual values are stored into?

Thanks in advance!

2 Answers, 1 is accepted

Sort by
0
John DeVight
Top achievements
Rank 1
answered on 13 Jan 2012, 09:59 PM
Hi Poque,

The data is stored in a DropDownList in the data attribute as an array of JSON objects.  For example, if I have a DropDownList called dropdownlist, to get the data for the DropDownList, I can use the following statement:

var data = $('#dropdownlist).data('tDropDownList').data;

Each object in the JSON array has 2 attributes, Text and Value.  So, to get the text and value for the first item in the DropDownList, you can do the following:

var data = $('#dropdownlist).data('tDropDownList').data;
var text = data[0].Text;
var value = data[0].Value;

Hope this helps.

Regards,

John DeVight
0
Ken Lewis
Top achievements
Rank 1
answered on 21 May 2012, 06:47 PM
Hi John,

I'm very grateful for your post. It is a very clear explanation and exactly what I needed.

Thanks!

Ken
Tags
ComboBox
Asked by
Poqwe
Top achievements
Rank 1
Answers by
John DeVight
Top achievements
Rank 1
Ken Lewis
Top achievements
Rank 1
Share this question
or