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

179

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

correct answers 1 Correct Answer

Adobe Community Professional , 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";

Likes

Translate

Translate
Adobe Community Professional ,
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

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
community guidelines
Adobe Community Professional ,
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

 

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
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?

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
community guidelines
Adobe Community Professional ,
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

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
community guidelines
Community Beginner ,
Apr 30, 2021 Apr 30, 2021

Copy link to clipboard

Copied

LATEST

Thank you!!

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