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

How do I copy the selected index of one combobox to another in jscript?

1 Answer 70 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 01 May 2012, 04:17 PM
I want to be able to copy the personal address controls values over to the shipping address controls when a user clicks a link button. I have the following javascript

function NewUserCopyPrsnlToShip()
    {
        text = $find("<%= txtPersonalAddress.ClientID %>").get_textBoxValue();
        $find("<%= txtShippingAddress.ClientID %>").set_value(text);

        text = $find("<%= txtPersonalAddress2.ClientID %>").get_textBoxValue();
        $find("<%= txtShippingAddress2.ClientID %>").set_value(text);

        text = $find("<%= txtPersonalCity.ClientID %>").get_textBoxValue();
        $find("<%= txtShippingCity.ClientID %>").set_value(text);

        document.getElementById("<%=rcbShippingState.ClientID%>").selectedIndex = document.getElementById("<%=rcbPersonalState.ClientID%>").selectedIndex;

        text = $find("<%= txtPersonalZip.ClientID %>").get_textBoxValue();
        $find("<%= txtShippingZip.ClientID %>").set_value(text);
    }

It all works except the combobox copy part. Both comboboxes are bound to the exact same collections. How do I make this work?

1 Answer, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 01 May 2012, 05:48 PM
Figured it out on my own (as usual)

var state = $find("<%=rcbPersonalState.ClientID%>").get_value();
        var stateTxt = $find("<%=rcbPersonalState.ClientID%>").get_text();

        $find("<%= rcbShippingState.ClientID %>").set_value(state);
        $find("<%= rcbShippingState.ClientID %>").set_text(stateTxt);
Tags
ComboBox
Asked by
Matt
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Share this question
or