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

setting label value to selected combobox value?

2 Answers 66 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Garrett
Top achievements
Rank 1
Garrett asked on 26 Sep 2013, 09:53 PM
HI there! Pretty simple question and probably very simple answer, haha.

I have a combo box that has a couple of values in it (Invoice, Quote). I also have a label or two.

I'd like to set the labels to whatever the combobox is currently set to.

By default the box is set to Invoice, so the page would go something like:

Is this an invoice or a quote? [RadComboBox:Invoice]
Ok, this will be marked as [Label:Invoice].


If the user clicks the combobox and selects Quote, I would like the label to also change to Quote without having to submit anything, just change the label on the fly as the combo box changes.

I assume I would need to use the RadComboBox_DropDownClosing function? 

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 1
answered on 27 Sep 2013, 03:20 AM
Hi Garrett,

Please try the following code snippet that I tried to change the label according to RadComboBox selectedItem in OnClientDropDownClosing event.

ASPX:
<telerik:RadComboBox ID="RadComboBox1" runat="server" OnClientDropDownClosing="OnClientDropDownClosing1">
    <Items>
        <telerik:RadComboBoxItem Text="Invoice" runat="server" Selected="true" />
        <telerik:RadComboBoxItem Text="Quote" runat="server" />
    </Items>
</telerik:RadComboBox>
<asp:Label ID="Label1" runat="server" Text="Invoice">
</asp:Label>

JavaScript:
<script type="text/javascript">  
 function OnClientDropDownClosing1(sender, args) {
        var label = document.getElementById("Label1");
        label.textContent = sender._selectedItem._text;
    }
</script>

Thanks,
Shinu.
0
Garrett
Top achievements
Rank 1
answered on 27 Sep 2013, 02:58 PM
Hi Shinu, 

thank you for your help, it seems that when I use your snippet the radcombobox stays open, never closing even when the control loses focus. I wonder if maybe I should use another event to trigger the change?

Edit: I just tried it in a new blank page and it worked, must be something I am doing wrong......I think it is because I am using a masterpage and it is somehow screwing with it........

I will look into this, thank you again Shinu
Tags
ComboBox
Asked by
Garrett
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Garrett
Top achievements
Rank 1
Share this question
or