Richselect from URL

I am trying to populate a richselect from an asp file. Currently I am using code similar to this:

{ view: "richselect", 
  id: "seriesname", 
  label: "from", 
  value: "1", 
  ycount: 3, 
  datatype: "json", 
  url: "getoptions.asp",
  on:{"onItemClick" : function(){$$('selectWithPopup_list').define('css','scrolling');}} 

where getoptions.asp returns the following:

[{ value: '1', label: 'Revenue' }]

However, the popup list displays the ‘1’ instead of the ‘Revenue’ from the json string.

Also, how would I return the label value from the richselect on form submit as $$(“seriesname”).getValue() at present returns [object].

Many thanks for any help offered.

Your JSON list is incorrect, it should be :-

[{ id: 1, value: 'Revenue' }, { id: 2, value: 'Something else' }]

To get the value (label text) of the selected item you need to reference the richselect’s “inner” list, and then use that id to lookup the value, like so :-

var id = $$('seriesname_list').getValue();
var value = $$('seriesname_list').item(id).value;

A richselect is not a list, it’s a component that uses a list. To reference the list used by a component you reference it as $$(‘listname_list’), i.e. add ‘_list’ to the component’s id / name.

(I think that’s all correct!)

Thanks for your help - the first bit worked after I modified the json, but I can’t get the second bit of code to return the selected value.

Of course, I’ll experiment but if you have spotted a minor modification then I’d appreciate it.

Cheers.

Try :-

var id = $$('seriesname').getValue();
var value = $$('seriesname_list').item(id).value;

Got it!

the getvalue has to come from the richselect id and not it’s list:

var id = $$('seriesname').getValue();
var value = $$('seriesname_list').item(id).value;

You have been most helpful - thank you.

Hahaha - we got there at the same time - many thanks.