Skip to main content
New Participant
April 29, 2021
Answered

Change text field based on another field's value

  • April 29, 2021
  • 2 replies
  • 3722 views

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?

 

This topic has been closed for replies.
Correct answer Thom Parker

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";

 

2 replies

Nesa Nurani
Community Expert
April 29, 2021

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

 

New Participant
April 29, 2021

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?

Thom Parker
Thom ParkerCorrect answer
Community Expert
April 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";

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
Community Expert
April 29, 2021

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 PDFScriptingUse the Acrobat JavaScript Reference early and often