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

what is proper way to get list of checked items in javascript?

3 Answers 1660 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 16 May 2017, 04:12 PM
I used javascript debugger and did find an object to get the "checked" items in my RadComboBox.
what is the proper way to do this so I can clean up my code?
in my case I am getting the list of categories to send to RadScheduler provider

    window.OnClientAppointmentsPopulating = function (sender, eventArgs) {
        var combobox = $find("<%=ddlCatToShow.clientID %>");
        var list = "";
        var items = combobox.get_items();
        var array = combobox._checkedIndices.toString().split(','
        for (var i = 0; i < array.length-1; i++) { 
      
            var item = items.getItem(array[i]);
        //alert(item.get_text()); 
        //alert(item.get_value());   
            list += item.get_value() + ",";
        
        eventArgs.get_schedulerInfo().CategoryList = list.replace(/,\s*$/, "");
};


3 Answers, 1 is accepted

Sort by
0
Loïc
Top achievements
Rank 1
answered on 19 May 2017, 08:22 AM

Hi Doug,

The best proper way to get list of checked items in javascript is to call the ".get_checkedItems()" method of your RadComboBox.

var combobox = $find("<%=ddlCatToShow.clientID %>");
var checkedItems = combobox.get_checkedItems();
 
for (var i = 0; i < checkedItems.length; i++) {
  // Your code here
}

 

More information here : RadComboBox Object.

0
Karthik
Top achievements
Rank 1
answered on 08 Apr 2021, 02:52 PM

When I try to access the radcombobox in document onload, I receiving the object as null in IE11 only. (works in edge, chrome and FF)

what is the best approach to access the radcombobox in document onload for IE.

$(document).ready(function () {
var combo = $find("<%=EmailNotificationTypesComboBox.ClientID%>");
        var items = combo.get_items();
}

0
Vessy
Telerik team
answered on 12 Apr 2021, 07:06 PM

Hi Karthik,

The best way to ensure that the ComboBox is fully loaded before trying to access its client-side object (for all browsers) is to handle the control's OnClientLoad event:

https://docs.telerik.com/devtools/aspnet-ajax/controls/combobox/client-side-programming/events/onclientload

For example:

 <script>
            function onComboLoad(combo, args) {
                var items = combo.get_items();
            }
        </script>
        <telerik:RadComboBox ID="EmailNotificationTypesComboBox" runat="server" OnClientLoad="onComboLoad">
           ...
        </telerik:RadComboBox>

Regards,
Vessy
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ComboBox
Asked by
Doug
Top achievements
Rank 1
Answers by
Loïc
Top achievements
Rank 1
Karthik
Top achievements
Rank 1
Vessy
Telerik team
Share this question
or