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

Hiding text when one or more variables are null

Community Beginner ,
Nov 15, 2022 Nov 15, 2022

Copy link to clipboard

Copied

Good morning, community!

 

I have a description field that is made up of three components:

  1. Commodity name (var. 1)
  2. Quantiy (var. 2)
  3. Container Size (var. 3)

This populates in a descriptor in a notes area as "-- [Commodity name (##qty. x Container Size)] --"

 

My current script is:

event.value = "-- [" + this.getField("Commodity_Line1").valueAsString + " (" + this.getField("Qty_Line1").valueAsString + "qty. x " + this.getField("Container_Line1").valueAsString + ")] -- ";

 

However, I would like to hide the descriptor when one or more of the above variables are null.

Any guidance will be greatly appreciated.

TOPICS
JavaScript , PDF forms

Views

783

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

correct answers 1 Correct answer

Community Expert , Nov 15, 2022 Nov 15, 2022

Try this script:

 

if (this.getField("Commodity_Line1").value != this.getField("Commodity_Line1").defaultValue && this.getField("Qty_Line1").value != this.getField("Qty_Line1").defaultValue && this.getField("Container_Line1").value != this.getField("Container_Line1").defaultValue) {
event.value = "-- [" + this.getField("Commodity_Line1").valueAsString + " (" + this.getField("Qty_Line1").valueAsString + "qty. x " + this.getField("Container_Line1").valueAsString + ")] -- ";}
else {event.target.value

...

Votes

Translate

Translate
Community Expert ,
Nov 15, 2022 Nov 15, 2022

Copy link to clipboard

Copied

Try this script:

 

if (this.getField("Commodity_Line1").value != this.getField("Commodity_Line1").defaultValue && this.getField("Qty_Line1").value != this.getField("Qty_Line1").defaultValue && this.getField("Container_Line1").value != this.getField("Container_Line1").defaultValue) {
event.value = "-- [" + this.getField("Commodity_Line1").valueAsString + " (" + this.getField("Qty_Line1").valueAsString + "qty. x " + this.getField("Container_Line1").valueAsString + ")] -- ";}
else {event.target.value = event.target.defaultValue;}

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
Community Beginner ,
Nov 16, 2022 Nov 16, 2022

Copy link to clipboard

Copied

LATEST

Thanks, JR!

That's exactly what I was looking for.

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