When I click on a checkbox, my text is updated correctly.
On page load, the text area includes the Text value of the first Item.
How can I get the Text to display correctly on page load?.
<telerik:RadComboBox
ID="rcbDocType" Runat="server"
AutoPostBack="false"
>
<ItemTemplate>
<div onclick="StopPropagation(event)" class="combo-item-template">
<asp:CheckBox runat="server" ID="cbItem" Checked="false" onclick="onCheckBoxClick(this)" />
<asp:Label runat="server" ID="lblItem" AssociatedControlID="cbItem">
</asp:Label>
</div>
</ItemTemplate>
</telerik:RadComboBox>
function onCheckBoxClick(chk) {
var combo = $find("<%= rcbDocType.ClientID %>");
//holds the text of all checked items
var text = "";
//holds the values of all checked items
var values = "";
//get the collection of all items
var items = combo.get_items();
//enumerate all items
for (var i = 0; i < items.get_count(); i++) {
var item = items.getItem(i);
//get the checkbox element of the current item
var chk1 = $get(combo.get_id() + "_i" + i + "_cbItem");
if (chk1.checked) {
if (text == "") {
text = item.get_text();
}
else {
text = "[Multi]";
}
values += item.get_value() + ",";
}
}
//remove the last comma from the string
values = removeLastComma(values);
if (text.length > 0) {
//set the text of the combobox
combo.set_text(text);
}
else {
//all checkboxes are unchecked
//so reset the controls
combo.set_text("");
}
}
//this method removes the ending comma from a string
function removeLastComma(str) {
return str.replace(/,$/, "");
}
function StopPropagation(e) {
//cancel bubbling
e.cancelBubble = true;
if (e.stopPropagation) {
e.stopPropagation();
}
}