In: Computer Science
Form for a user to enter billing and shipping information. Checkbox that when clicked copies all of the billing information to the shipping information. A submit button to make sure the text fields have been filled. Just trying to make a simple small webpage to order a couple Items like toys for instance nothing fancy or big just small and simple, a couple of text fields. That's all
JavaScript/HTML
Hi,
Please find the below code for transfer the Shipping Information to Billing information which clicked on the Checkbox - Billing Same as Shipping
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
    <style>
        #inline {
            width: 100%;
            height: auto;
            background-color: honeydew;
            display: flex;
        }
        .one, .two {
            width: 50%;
            height: 100px;
            background-color: green;
            margin: 10px;
        }
        .block_container {
            text-align: left;
            padding-left: 10px;
            margin-left: 10px;
        }
        .block {
            width: 100px;
        }
    </style>
    <script>
        //THis event will fire when HTML controls loaded in browser and ready for use as DOM
        $(document).ready(readyFn);
        function readyFn(n) {
            //Find out the Check Box - Billing Same as Shipping
            var chkIsBillingSameAsShipping = $("#chkBillingSameAsShipping");
            //attach click event on the checkox
            chkIsBillingSameAsShipping.off("click").on("click", function () {
                //This will excute when Chckbox is clicked
                var checkedOrNot = $(this).prop("checked");
                //If Checkbox is Checked then below code executes
               
                if (checkedOrNot) {
                     //Copy Infomation from Shipping Address to Billing Address
                    $("#txtBillingAddressline1").val($("#txtShippingAddressline1").val());  
                    $("#txtBillingAddressline2").val($("#txtShippingAddressline2").val());
                    $("#txtBillingCity").val($("#txtShippingCity").val());
                    $("#txtBillingState").val($("#txtShippingState").val());
                    $("#txtBillingCountry").val($("#txtShippingCountry").val());
                    $("#txtBillingPostalCode").val($("#txtShippingPostalCode").val());
                }
                //If checkbx is Unchecked then below code executes
                else {
                    //Clear Billing Address Information
                    $("#txtBillingAddressline1").val("");
                    $("#txtBillingAddressline2").val("");
                    $("#txtBillingCity").val("");
                    $("#txtBillingState").val("");
                    $("#txtBillingCountry").val("");
                    $("#txtBillingPostalCode").val("");
                }
            })
        }
    </script>
</head>
<body>
    <div id="inline">
        <div id="dvShippingInfo" class="block_container">
            <h1>Shipping Info</h1><br />
            <div class="block">Address Line1:</div> <input type="text" id="txtShippingAddressline1" style="height:20px;width:150px" /><br />
            <div class="block">Address Line2: </div><input type="text" id="txtShippingAddressline2" style="height:20px;width:150px" /><br />
            <div class="block">City: </div><input type="text" id="txtShippingCity" style="height:20px;width:150px" /><br />
            <div class="block">State:</div> <input type="text" id="txtShippingState" style="height:20px;width:150px" /><br />
            <div class="block">Country:</div> <input type="text" id="txtShippingCountry" style="height:20px;width:150px" /><br />
            <div class="block">Postal Code: </div><input type="text" id="txtShippingPostalCode" style="height:20px;width:150px" /><br />
        </div>
        <div id="dvShippingInfo" class="block_container">
            <h1>Billing Info</h1><br />
            <div class="block">Address Line1:</div> <input type="text" id="txtBillingAddressline1" style="height:20px;width:150px" /><br />
            <div class="block">Address Line2: </div><input type="text" id="txtBillingAddressline2" style="height:20px;width:150px" /><br />
            <div class="block">City: </div><input type="text" id="txtBillingCity" style="height:20px;width:150px" /><br />
            <div class="block">State:</div> <input type="text" id="txtBillingState" style="height:20px;width:150px" /><br />
            <div class="block">Country:</div> <input type="text" id="txtBillingCountry" style="height:20px;width:150px" /><br />
            <div class="block">Postal Code: </div><input type="text" id="txtBillingPostalCode" style="height:20px;width:150px" /><br />
        </div>
    </div>
    <div>
        Billing Same as Shipping?: <input type="checkbox" id="chkBillingSameAsShipping">
    </div>
</body>
</html>
Below is the output;

