Skip to main content
Participating Frequently
August 1, 2018
Answered

Conditional pdf form dependent on text

  • August 1, 2018
  • 3 replies
  • 547 views

Hi,

i was was wondering if someone would be able to help me as I pretty much have zero coding ability and my attempts and bodging code together from different questions hasn’t gone as planned.  I am trying to set up  3 boxes named ‘am’, ‘pm’ and ‘eve’.  I would like it that when all 3 of these boxes contain any text that another box goes green, and that if any of those boxes is empty that the box is red.  I am Going to have to have one of these for every day so if there was a way of copying the boxes down that would automatically update the validation script that would be amazing.  If anyone can help thank you in advance.

This topic has been closed for replies.
Correct answer try67

You can use this code as the field's custom calculation script:

event.target.fillColor = (this.getField("am").valueAsString!="" && this.getField("pm").valueAsString!="" && this.getField("eve").valueAsString!="") ? color.green : color.red;

After you apply the script you can copy & paste the field (and then rename it) or use the Create Multiple Copies command to generate new copies with unique names.

3 replies

tboden85Author
Participating Frequently
August 2, 2018

Thank you both so much

Thom Parker
Community Expert
Community Expert
August 1, 2018

Add this script to the box that needs to change colors

if(this.getField("am").valueAsString.length && this.getField("am").valueAsString.length && this.getField("am").valueAsString.length)

   event.target.strokeColor = color.green;

else

    event.target.strokeColor = color.red;

This will only work if the border width is set to something greater then 0

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 1, 2018

You can use this code as the field's custom calculation script:

event.target.fillColor = (this.getField("am").valueAsString!="" && this.getField("pm").valueAsString!="" && this.getField("eve").valueAsString!="") ? color.green : color.red;

After you apply the script you can copy & paste the field (and then rename it) or use the Create Multiple Copies command to generate new copies with unique names.