Skip to main content
first.officer
Inspiring
November 20, 2019
Answered

Simple JavaScript to compare field values

  • November 20, 2019
  • 1 reply
  • 2661 views

Hi all,

Am trying to come up with some JS cstom calc. script for comparing two numerical field values (Fields "A" and "B"). If A=B, then i want to colour this field GREEN, and if they dont match, colour RED. 

 

I just can't seem to get an answer, haven't done any form building for a while and forgotten what little i knew it seems!.

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

Exactly what field needs to be turned green?  

Let's say it's the B field. Put this script in the custom calculation script for B

 

if(event.value == this.getField("A").value)

    event.target.fillColor = color.green;

else

    event.target.fillColor = ["T"];

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
November 20, 2019

Exactly what field needs to be turned green?  

Let's say it's the B field. Put this script in the custom calculation script for B

 

if(event.value == this.getField("A").value)

    event.target.fillColor = color.green;

else

    event.target.fillColor = ["T"];

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
first.officer
Inspiring
November 20, 2019

Many thanks Thom....totally forgotten all the things i used to know (not that it was ever a great deal!)