How can we copy the billing address information to shipping information with an checkbox in online form

Soultion : Here the requirement of the task is like we need to had a checkbox if the checkbox was checked then the billing information need to come in below shipping address by using checkbox
code for this soultion 
document.addEventListener("DOMContentLoaded", function() {
    var checkbox = document.getElementById('Shipping');
    checkbox.addEventListener('change', function() {
        var billCompany = document.getElementById('billCompany').value;
        var billName = document.getElementById('billName').value;
        var billEmail = document.getElementById('email').value;
        var billPhone = document.getElementById('billPhone').value;
        var billState = document.getElementById('billState').value;
        var billStreet = document.getElementById('billStreet').value;
        console.log('dsfdas', billState);
        var billAddress = document.getElementById('billAddress').value;
        var billCountry = document.getElementById('billCountry').value;
        var billZip = document.getElementById('billZip').value;
        var city = document.getElementById('city').value;
 
        // Check if the checkbox is checked
        if (Shipping.checked) {
            document.getElementById('shipCompany').value = billCompany;
            document.getElementById('shipName').value = billName;
            document.getElementById('shipStreet').value = billStreet;
            document.getElementById('shipAddress').value = billAddress;
            document.getElementById('shipCountry').value = billCountry;
            document.getElementById('shipZip').value = billZip;
            document.getElementById('shipCity').value = city;
            document.getElementById('shipState').value = billState;
        } else {
            // If the checkbox is unchecked, clear the shipping details
            document.getElementById('shipCompany').value = '';
            document.getElementById('shipName').value = '';
            document.getElementById('shipStreet').value = '';
            document.getElementById('shipAddress').value = '';
            document.getElementById('shipCountry').value = '';
            document.getElementById('shipZip').value = '';
            document.getElementById('shipCity').value = '';
            document.getElementById('shipState').value = '';
        }
    });

Leave a comment

Your email address will not be published. Required fields are marked *