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

[Solved] identify the sender combo in the checkbox click event

2 Answers 93 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
newbie
Top achievements
Rank 1
newbie asked on 13 Apr 2009, 10:17 PM
I have a multi-select combo box using checkboxes.

I have this code in the click event of the checkbox to set the text of the combo:

function

stopPropagation(e)

 

{

e.cancelBubble =

true;

 

 

if (e.stopPropagation)

 

{

e.stopPropagation();

}

 

 

var combo = $find("<%= RadComboBoxType.ClientID %>");

 

 

var selectedItemsTexts = "";

 

 

var selectedItemsValues = "";

 

 

 

var items = combo.get_items();

 

 

for (var i = 0; i < items.get_count(); i++)

 

{

 

var item = items.getItem(i);

 

 

var checkbox = item.get_element().getElementsByTagName("input")[0];

 

 

if (checkbox.checked)

 

{

selectedItemsTexts += item.get_text() +

", ";

 

selectedItemsValues += item.get_value() +

", ";

 

}

}

 

selectedItemsTexts = selectedItemsTexts.substring(0, selectedItemsTexts.length - 2);

selectedItemsValues = selectedItemsValues.substring(0, selectedItemsValues.length - 2);

 

 

combo.set_text(selectedItemsTexts);

 

 

//Clear the selection that RadComboBox has made internally.

 

 

if (selectedItemsValues == "")

 

{

combo.clearSelection();

}

}



I have multiple multi-select combos on my page and therefore I want to identify the sender combo and set text in that combo accordingly, instead of hardcoding the RadComboBox name.

How can I do that?

2 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 14 Apr 2009, 08:01 AM
Hello,

Here is how you can do this:

<telerik:RadComboBox ID="RadComboBox1" runat="server"
<ItemTemplate> 
    <asp:CheckBox ID="CheckBox1" runat="server" onclick="updateCombo(this)" Text='<%# DataBinder.Eval(Container, "Text") %>' /> 
</ItemTemplate> 
<Items> 
    <telerik:RadComboBoxItem Text="item 1" /> 
    <telerik:RadComboBoxItem Text="item 2" /> 
    <telerik:RadComboBoxItem Text="item 3" /> 
</Items> 
</telerik:RadComboBox> 
 
<script type="text/javascript"
    function updateCombo(chk) 
    { 
        //example: chk.id = RadComboBox1_i1_CheckBox1      
        var comboID = chk.id.replace(/_i(\d+)_CheckBox1$/, ""); 
        var combo = $find(comboID); 
        combo.set_text("your text"); 
    } 
</script> 


Best wishes,
Veselin Vasilev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
newbie
Top achievements
Rank 1
answered on 14 Apr 2009, 05:22 PM

Thanks that helped.

 

Tags
ComboBox
Asked by
newbie
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
newbie
Top achievements
Rank 1
Share this question
or