Copy link to clipboard
Copied
I am trying to put together address fields (company, address, address2, city, state, zip code) into 1 field and am using the following script:
event.value = this.getField("shipper_name").value + "\n" + this.getField("shipper_address1").value + "\n" + this.getField("shipper_address2").value + "\n" + this.getField("shipper_city").value + ", " + this.getField("shipper_state").value + " " + this.getField("shipper_postal_code").value;
Right now - if the company has no shipper_address2 it still adds the line to the field so it looks like this:
ABC Company
123 Main Street
Anywhere, CA 90210
What I would like it to look like is:
ABC Company
123 Main Street
Anywhere, CA 90210
How can I accomplish this?
I believe I should use if/then statements but am not too clear how.
Copy link to clipboard
Copied
You can do it like this:
event.value = this.getField("shipper_name").value + "\n" + this.getField("shipper_address1").value + "\n";
if (this.getField("shipper_address2").value!="")
event.value += this.getField("shipper_address2").value + "\n";
event.value += this.getField("shipper_city").value + ", " + this.getField("shipper_state").value + " " + this.getField("shipper_postal_code").value;