Reputation: 1054
We have billing address section and shipping address section.
On the shipping address section, we have a checkbox that asks users to check the box if shipping address is same as billing address.
If same and the box is checked, billing address info is supposed to be copied to shipping address box.
I have tried a couple of examples on this forum. They did not work for me.
My own version is not working for me.
Any ideas what's wrong?
<script type="text/javascript">
$("#same_as_billingaddr").on("change", function(){
if (this.checked) {
$("[name='txtfullname']").val($("[name='txtfname']").val());
$("[name='txtaddress']").val($("[name='txtfaddress']").val());
$("[name='txtcity']").val($("[name='txtfcity']").val());
$("[name='ddlfillstates']").val($("[name='ddlstates']").val());
$("[name='txtzip']").val($("[name='txtfzip']").val());
}
});
</script>
<tr>
<td style="border-collapse: collapse;border: 1px solid black;"><div class="auto-style7"><label<asp:CheckBox ID="same_as_taxpayeraddr" runat="server" />Check box if shipping address is same as billing</label><br />
OTHERWISE, PLEASE CORRECT IN SPACE PROVIDED BELOW</div></td>
</tr>
Upvotes: 0
Views: 933
Reputation: 62280
If this is ASP.NET Web Form, you need to access a control's Id as <%= same_as_billingaddr.ClientID %>
at client-side.
<asp:CheckBox runat="server" ID="same_as_billingaddr" />
<asp:TextBox runat="server" ID="txtfname" />
<asp:TextBox runat="server" ID="txtfullname" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
$("#<%= same_as_billingaddr.ClientID %>").on("change", function () {
if (this.checked) {
$("#<%= txtfullname.ClientID %>").val($("#<%= txtfname.ClientID %>").val());
}
});
</script>
Upvotes: 1