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

Get RadComboBox check values as string

2 Answers 348 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Max
Top achievements
Rank 1
Max asked on 05 May 2016, 02:54 PM

I have a RadComboBox with checkboxes and I want to get all the values in the DataValueField as a comma separated string.

$get("myComboBox").value gets me a comma separated string of the DataTextField and not the DataValueField.

How do I do this?

2 Answers, 1 is accepted

Sort by
0
Max
Top achievements
Rank 1
answered on 05 May 2016, 03:07 PM
I mean to ask how I do it client-side
0
Ivan Zhekov
Telerik team
answered on 06 May 2016, 10:55 AM
Hi, Max.

It's actually really simple: you just loop over the checked indices, then push the values inside an array and finally join the array e.g.:

function getValuesGeneric( combobox ) {
 
    var values = [];
    var items = combobox.get_items();
 
    Array.forEach( combobox.get_checkedIndices(), function( element, index ) {
        var item = items.getItem( element );
        values.push( item.get_value() );
    });
 
    alert( values.join(",") );
}

Where as combobox is the client-side object.

I've also attached a simple page with the code.


Regards,
Ivan Zhekov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
ComboBox
Asked by
Max
Top achievements
Rank 1
Answers by
Max
Top achievements
Rank 1
Ivan Zhekov
Telerik team
Share this question
or