How can I combine fields but only include a field if it has a value

New Here ,
May 21, 2019

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.

TOPICS
Acrobat SDK and JavaScript

Views

52

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How can I combine fields but only include a field if it has a value

New Here ,
May 21, 2019

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.

TOPICS
Acrobat SDK and JavaScript

Views

53

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 21, 2019 0
try67 LATEST
Most Valuable Participant ,
May 22, 2019

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;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 22, 2019 0