Get the id of an selected item

Hi,

Is it possible to get the ID or the name of an selected item in a richselect?

When var test = $$(‘richselect1’).getValue();
alert (test)

is triggered, it only displays the value, but i need its ID or name…

Is this possible?

Regards Simon

Hi,

options of the richselect contains two properties:

“value” - option key
“label” - the visible text

getValue() returns “value”

for example

{ view:“richselect”, id:‘richselect1’, value: “1”, yCount:“3”, options:[
{ value:“1”, label:“One” },
{ value:“2”, label:“Two” },
{ value:“3”, label:“Three” }
]},

To get other properties of the selected item you may use the following approach:

var value = $$(“richselect1”).getValue();
var list = $$(“richselect1”).getList();
var item = list.item(value);

var label = item.label;

But is it also possible to get the id of the selected element?

eg:
{ view:“richselect”, id:‘richselect1’, value: “1”, yCount:“3”, options:[
{ value:“1”, label:“One”, id:“1” },
{ value:“10”, label:“10”, id:“2” },

and get the id of value 10?

Thnx in advance.
regards,
Simon

to get the id of the selected element?
var value = $$(“richselect1”).getValue();

“value” will contain id of selected item

and get the id of value 10?
You data config is a bit confusing, if you change it as

{ value:"1", label:"One", myid:"1" }, { value:"10", label:"10", myid:"2" },

then you will be able to use

var value = $$("richselect1").getValue(); var myid = $$("richselect1_list").item(value).myid;

Hi Stanislav,
Thnx for the response.

I´ve tried to apply your solution to my project, but it really does not work…
I even tried it, setting up a new project with just one selectbox using this code:

var ui = dhx.ui({
view:“richselect”, id:“select”, yCount:“2”, options:[
{ value:“a”, label:“One”, myid:“1” },
{ value:“b”, label:“10”, myid:“2” }
]});

$$(“select”).attachEvent(‘onChange’, function (){
var value = $$(“select”).getValue();
var myid = $$(“select_list”).item(value).myid;
alert (myid);

});

the alert that pops up is ´Undefined´.

Can you please confirm if this is correct?

Thnx in advance!

Sorry for misleading info, the list must work with above code but in reality it doesn’t work. :frowning:

Try to change your code as

[code]var data = [
{ id:“a”, value:“One”, myid:“1” },
{ id:“b”, value:“10”, myid:“2” }
];

var ui = dhx.ui({
view:“richselect”, id:“select”, yCount:“2”
});
$$(‘select_list’).parse(data);[/code]

After such init list will preserve all custom attributes