• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
May 21, 2019 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

242

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
community guidelines
Community Expert ,
May 22, 2019 May 22, 2019

Copy link to clipboard

Copied

LATEST

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;

Votes

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
community guidelines