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

2 posts, 0 answers
  1. Matt
    Matt avatar
    23 posts
    Member since:
    Mar 2011

    Posted 01 May 2012 Link to this post

    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?
  2. Matt
    Matt avatar
    23 posts
    Member since:
    Mar 2011

    Posted 01 May 2012 Link to this post

    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);
Back to Top