Agent67
Honorary Master
I'm trying to have my billing address fields auto-populated by the shipping address fields' values. And that works, but my next problem is to prevent the auto-population from happening if some of/all of the shipping address values are empty. I've tried using plain truthy values like
and checking for "" and null. But none of that seems to be working, it still just auto-populates the billing fields anyway?
Current code I'm using:
JavaScript:
if (variableLOL)
{
console.log("we are truthy")
}
and checking for "" and null. But none of that seems to be working, it still just auto-populates the billing fields anyway?
Current code I'm using:
JavaScript:
// shipping and billing address field elements
let shipping_street_num = document.getElementById("shipping_street_num");
let shipping_street_name = document.getElementById("shipping_street_name");
let shipping_city = document.getElementById("shipping_city");
let shipping_postal_code = document.getElementById("shipping_postal_code");
let billing_street_num = document.getElementById("billing_street_num");
let billing_street_name = document.getElementById("billing_street_name");
let billing_city = document.getElementById("billing_city");
let billing_postal_code = document.getElementById("billing_postal_code");
let sameShipBillButton = document.getElementById("same_opt");
// Shipping and Billing address function, if the checkbox is clicked then the Billing address section
// is auto-populated and disabled
sameShipBillButton.addEventListener("click", () => {
if (sameShipBillButton.checked)
{
if ((shipping_city !== "" || shipping_city !== null) && (shipping_postal_code !== "" || shipping_postal_code !== null)
&& (shipping_street_name !== "" || shipping_street_name !== null) && (shipping_street_num !== "" || shipping_street_num !== null))
{
billing_street_num.value = shipping_street_num.value;
billing_street_name.value = shipping_street_name.value;
billing_city.value = shipping_city.value;
billing_postal_code.value = shipping_postal_code.value;
billing_postal_code.disabled = true;
billing_city.disabled = true;
billing_street_num.disabled = true;
billing_street_name.disabled = true;
}
}
else
{
billing_street_num.value = "";
billing_street_num.disabled = false;
billing_street_name.value = "";
billing_street_name.disabled = false;
billing_city.value = "";
billing_city.disabled = false;
billing_postal_code.value = "";
billing_postal_code.disabled = false;
}
});
