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

Change text field based on another field's value

Community Beginner ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Hi - I'm trying to get a text field to show "Owed to Us" if the amount in another field is positive, and to show "Owed to Them" if the amount in that other field is negative. How do I do that?

 

TOPICS
Create PDFs , How to , PDF forms

Views

1.5K

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 , Apr 29, 2021 Apr 29, 2021

Not exactly, in fact I had a syntax error in my code anyway (which is now fixed).

Since you have 3 conditions let's use an old fashion "if".

 

 

if(event.value < 0)
    this.getField("MessageField").value = "Owed to Them"
else if(event.value > 0)
    this.getField("MessageField").value = "Owed to Us";
else
    this.getField("MessageField").value = "Even Dealer Trade";

 

Votes

Translate

Translate
Community Expert ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

The best way to do this is to add a Validation script to the field that shows the positive or negative value. 

 

this.getField("MessageField").value = (event.value < 0)?"Owed to Them":"Owed to Us";

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Expert ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

You didn't specify what you want if value is 0?

Code provided by Thom will show "Owed to us" when value is 0 or if field is empty, also code is missing '?' at:

(event.value < 0)?"Owed

 

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 ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Thank you! If the Value is 0 it should say "Even Dealer Trade" - So if I understand this correctly, would I need to write

 

this.getField("MessageField").value = (event.value < 0)"Owed to Them":"Owed to Us"

this.getField("MessageField).value = (event.value = 0)"Even Dealer Trade"

 

Or is there some and / or connection that I need to also insert?

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 Expert ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Not exactly, in fact I had a syntax error in my code anyway (which is now fixed).

Since you have 3 conditions let's use an old fashion "if".

 

 

if(event.value < 0)
    this.getField("MessageField").value = "Owed to Them"
else if(event.value > 0)
    this.getField("MessageField").value = "Owed to Us";
else
    this.getField("MessageField").value = "Even Dealer Trade";

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Apr 30, 2021 Apr 30, 2021

Copy link to clipboard

Copied

LATEST

Thank you!!

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