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

How to change ComboBox Selected Value from other ComboBox Selected Value

2 Answers 362 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Myo
Top achievements
Rank 1
Myo asked on 28 Mar 2014, 09:02 AM
Hi
Anybody can help me how to change combobox selected value from another combobox selected value when click button (Copy from Mailing). I would like to publish my code and attached with image what i want to do. Appreciate for any help.

Client Side
(
 function bindEventHandlers() {
            $telerik.$('#btnCopyFromBilling').unbind('click').bind('click', function () {
                oncopyfrombilling('COPYBILLING');
            });
            $telerik.$('#btnCopyFromMailing').unbind('click').bind('click', function () {
                oncopyfrombilling('COPYMAILING');
            });
        }
function selectRadComboboxByValue(radcombo, value) {
            radcombo.set_selectedIndex(value);
            debugger
        }
        function oncopyfrombilling(args) {
            var txtAreaBillingAddress = $get('<%=txtAreaBillingAddress.ClientID%>');
            var ddlBillingRegion = $find('<%=ddlBillingRegion.ClientID%>');
            var ddlBillingCity = $find('<%=ddlBillingCity.ClientID%>');
            var txtBillingPostal = $get('<%=txtBillingPostal.ClientID%>');
            var ddlBillingCountry = $find('<%=ddlBillingCountry.ClientID%>');
            
            var txtAreaMailingAddress = $get('<%=txtAreaMailingAddress.ClientID%>');
            var ddlMailingRegion = $find('<%=ddlMailingRegion.ClientID%>');
            var ddlMailingCity = $find('<%=ddlMailingCity.ClientID%>');
            var txtMailingPostal = $get('<%=txtMailingPostal.ClientID%>');
            var ddlMailingCountry = $find('<%=ddlMailingCountry.ClientID%>');
            
            if (args === 'COPYMAILING') {
                alert(args);
                txtAreaBillingAddress.value = txtAreaMailingAddress.value;
                ddlBillingRegion.set_value(ddlMailingRegion.get_value());
                ddlBillingCity.set_value(ddlMailingCity.get_value());
                txtBillingPostal.value = txtMailingPostal.value;
                ddlBillingCountry.set_value(ddlMailingCountry.get_value());
            }
 else if (args === 'COPYBILLING') {
                txtAreaMailingAddress.value = txtAreaMailingAddress.value;
                ddlMailingRegion.set_value(ddlBillingRegion.get_value());
                ddlMailingRegion.set_value(ddlBillingCity.get_value());
                ddlMailingRegion.value = txtBillingPostal.value;
                ddlMailingRegion.set_value(ddlBillingCountry.get_value());
            }
)

ASPX
(
<div class="divStatusAddressFieldSet" id="BillingMailing">
                        <div class="divEmptyRow">
                        </div>
                        <fieldset class="longestFieldset">
                            <legend>
                                <u>5</u>. Billing Address
                            </legend>
                            <div class="divFormControls">
                                <div class="divText">
                                </div>
                                <div class="divInput">
                                    <input type="button" id="btnCopyFromMailing" value="Copy from Mailing (X) " />
                                </div>
                            </div>
                            <div class="divLongFormControls">
                                <div class="divText">
                                    <label>
                                        Address
                                    </label>
                                </div>
                                <div class="divInput">
                                    <textarea id="txtAreaBillingAddress" runat="server" style="height: 95%; width: 96%"></textarea>
                                </div>
                            </div>
                            <div class="divFormControls">
                                <div class="divText">
                                    <label>
                                        Region
                                    </label>
                                </div>
                                <div class="divInput">
                                    <telerik:RadComboBox ID="ddlBillingRegion" runat="server" Skin="Default" ShowDropDownOnTextboxClick="true"
                                                         EmptyMessage="Region" Width="100%" Font-Size="11px" EnableLoadOnDemand="true">
                                        <HeaderTemplate>
                                            <asp:Label ID="lblRegion" runat="server" Text="Region" Font-Bold="true" Font-Size="11px"></asp:Label>
                                        </HeaderTemplate>
                                    </telerik:RadComboBox>
                                   <%-- <telerik:RadDropDownList ID="ddlBillingRegion" runat="server"></telerik:RadDropDownList>--%>
                                </div>
                            </div>
                            <div class="divFormControls">
                                <div class="divText">
                                    <label>
                                        City
                                    </label>
                                </div>
                                <div class="divInput">
                                   <telerik:RadComboBox ID="ddlBillingCity" runat="server" Skin="Default" ShowDropDownOnTextboxClick="true"
                                                         EmptyMessage="City" Width="100%" Height="300px" Font-Size="11px" EnableLoadOnDemand="true">
                                        <HeaderTemplate>
                                            <asp:Label ID="lblBillingCity" runat="server" Text="City" Font-Bold="true" Font-Size="11px"></asp:Label>
                                        </HeaderTemplate>
                                    </telerik:RadComboBox>
                                    <%-- <telerik:RadDropDownList ID="ddlBillingCity" runat="server"></telerik:RadDropDownList>--%>
                                </div>
                            </div>
                            <div class="divFormControls">
                                <div class="divText">
                                    <label>
                                        Postal/Zip code
                                    </label>
                                </div>
                                <div class="divInput">
                                    <input type="text" id="txtBillingPostal" runat="server" />
                                </div>
                            </div>
                            <div class="divFormControls">
                                <div class="divText">
                                    <label>
                                        Country
                                    </label>
                                </div>
                                <div class="divInput">
                                  <telerik:RadComboBox ID="ddlBillingCountry" runat="server" Skin="Default" ShowDropDownOnTextboxClick="true"
                                                         EmptyMessage="Country" Width="100%" Font-Size="11px" EnableLoadOnDemand="true">
                                        <HeaderTemplate>
                                            <asp:Label ID="lblGuestCountry" runat="server" Text="Nationality" Font-Bold="true"
                                                       Font-Size="11px"></asp:Label>
                                        </HeaderTemplate>
                                    </telerik:RadComboBox>
                                    <%--  <telerik:RadDropDownList ID="ddlBillingCountry" runat="server" ></telerik:RadDropDownList>--%>
                                </div>
                            </div>
                        </fieldset>
                        <div class="divEmptyRow">
                        </div>
                        <fieldset class="longestFieldset">
                            <legend>
                                <u>6</u>. Mailing Address
                            </legend>
                            <div class="divFormControls">
                                <div class="divText">
                                </div>
                                <div class="divInput">
                                    <input type="button" id="btnCopyFromBilling" value="Copy from billing (Y) " />
                                </div>
                            </div>
                            <div class="divLongFormControls">
                                <div class="divText">
                                    <label>
                                        Address
                                    </label>
                                </div>
                                <div class="divInput">
                                    <textarea id="txtAreaMailingAddress" runat="server" style="height: 95%; width: 96%"></textarea>
                                </div>
                            </div>
                            <div class="divFormControls">
                                <div class="divText">
                                    <label>
                                        Region
                                    </label>
                                </div>
                                <div class="divInput">
                                    <telerik:RadComboBox ID="ddlMailingRegion" runat="server" Skin="Default" ShowDropDownOnTextboxClick="true"
                                                         EmptyMessage="Region" Width="100%" Font-Size="11px" EnableLoadOnDemand="true">
                                        <HeaderTemplate>
                                            <asp:Label ID="lblRegion" runat="server" Text="Region" Font-Bold="true" Font-Size="11px"></asp:Label>
                                        </HeaderTemplate>
                                    </telerik:RadComboBox>
                                </div>
                            </div>
                            <div class="divFormControls">
                                <div class="divText">
                                    <label>
                                        City
                                    </label>
                                </div>
                                <div class="divInput">
                                    <telerik:RadComboBox ID="ddlMailingCity" runat="server" Skin="Default" ShowDropDownOnTextboxClick="true"
                                                         EmptyMessage="City" Width="100%" Font-Size="11px" EnableLoadOnDemand="true">
                                        <HeaderTemplate>
                                            <asp:Label ID="lblMainlingCity" runat="server" Text="City" Font-Bold="true" Font-Size="11px"></asp:Label>
                                        </HeaderTemplate>
                                    </telerik:RadComboBox>
                                </div>
                            </div>
                            <div class="divFormControls">
                                <div class="divText">
                                    <label>
                                        Postal/Zip code
                                    </label>
                                </div>
                                <div class="divInput">
                                    <input type="text" id="txtMailingPostal" runat="server" />
                                </div>
                            </div>
                            <div class="divFormControls">
                                <div class="divText">
                                    <label>
                                        Country
                                    </label>
                                </div>
                                <div class="divInput">
                                    <telerik:RadComboBox ID="ddlMailingCountry" runat="server" Skin="Default" ShowDropDownOnTextboxClick="true"
                                                         EmptyMessage="Country" Width="100%" Height="300px" Font-Size="11px" EnableLoadOnDemand="true">
                                        <HeaderTemplate>
                                            <asp:Label ID="lblMailingCountry" runat="server" Text="Nationality" Font-Bold="true"
                                                       Font-Size="11px"></asp:Label>
                                        </HeaderTemplate>
                                    </telerik:RadComboBox>
                                </div>
                            </div>
                        </fieldset>
                    </div>
)
 

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Mar 2014, 10:54 AM
Hi Myo,

Please try the following code snippet to change the RadComboBox value based on the another RadComboBox selected value.

JavaScript:
<script type="text/javascript">
    function oncopyfrombilling() {
        var combo1 = $find("<%=ddlBillingRegion.ClientID %>");
        var combo2 = $find("<%=ddlMailingRegion.ClientID %>");
        var itemtext = combo1.get_selectedItem().get_text();
        var item = combo2.findItemByText(itemtext);
        if (item) {
            item.select();
        }
    }
</script>

Thanks,
Shinu.
0
Myo
Top achievements
Rank 1
answered on 30 Mar 2014, 07:25 AM
It is working now.Thanks alot shinu.
Tags
ComboBox
Asked by
Myo
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Myo
Top achievements
Rank 1
Share this question
or