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

Hiding text when one or more variables are null

Community Beginner ,
Nov 15, 2022 Nov 15, 2022

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
930
Translate
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
1 ACCEPTED SOLUTION
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 = event.target.defaultValue;}


Acrobate du PDF, InDesigner et Photoshoptographe

View solution in original post

Translate
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 ,
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 = event.target.defaultValue;}


Acrobate du PDF, InDesigner et Photoshoptographe
Translate
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
LATEST

Thanks, JR!

That's exactly what I was looking for.

Translate
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