JQuery not copying state dropdown list 1 to DDL2 on checkbox change

Posted by user1001411 on Stack Overflow See other posts from Stack Overflow or by user1001411
Published on 2011-10-18T15:49:50Z Indexed on 2013/10/29 9:54 UTC
Read the original article Hit count: 180

I've looked at similar posts on the subject but none of the recommended solutions have worked for me so I'm not sure where I'm going wrong. I have a billing and shipping address form with a dropdown list for the state. Upon checking/unchecking the "billing address same as shipping" everything copies over except the state dropdown list. The state dropdown list is populated from a SQLDataSource state table.

Here's my code:

<script type="text/javascript" language="javascript" src="../Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
  $('input:checkbox[id*=chkCopy]').change(function () {
    if ($(this).is(':checked')) {
      $('input:text[id*=TextBox5]').val($('input:text[id*=TextBox1]').val());
      $('input:text[id*=TextBox7]').val($('input:text[id*=TextBox2]').val());
      $('input:text[id*=TextBox9]').val($('input:text[id*=TextBox3]').val());
      $('input:text[id*=TextBox12]').val($('input:text[id*=TextBox4]').val());
      $('select#DropDownList6').val($("select#DropDownList1").val());
      $('input:text[id*=TextBox14]').val($('input:text[id*=TextBox6]').val());
    }
    else {
      $('input:text[id*=TextBox5]').val('');
      $('input:text[id*=TextBox7]').val('');
      $('input:text[id*=TextBox9]').val('');
      $('input:text[id*=TextBox12]').val('');
      $('select#DropDownList6').val('');
      $('input:text[id*=TextBox14]').val('');
    }
  });
});

and here is my SQL for the DDL:

<asp:DropDownList ID="DropDownList1" runat="server" DataTextField="Descr" DataValueField="ID" DataSourceID="SqlDataSource1" Width="254">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>" SelectCommand="SELECT * FROM [xrefState]">
</asp:SqlDataSource>

the other one:

<asp:DropDownList ID="DropDownList6" runat="server" DataTextField="Descr" DataValueField="ID" DataSourceID="SqlDataSource5" Width="254">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>" SelectCommand="SELECT * FROM [xrefState]">
</asp:SqlDataSource>

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about checkbox