Skip to main content
Participant
March 8, 2017
Question

Script to change text field's fill color depending on text entered

  • March 8, 2017
  • 1 reply
  • 3219 views

Hi All,

I am working on a creating a PDF form with text fields that need to change the fill color depending on values entered (value 1 turns fill color red, value 2 turns fill color green, value 3 turns fill color blue, etc.). I was wondering if it is possible to write a JavaScript which will set the text field's background color to the color required based on the numeric value entered. Any ideas?

Thank you,

Donna    

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
March 8, 2017

Yes, it is. You can use this code as the field's custom validation script:

if (event.value=="1") event.target.fillColor = color.red;

else if (event.value=="2") event.target.fillColor = color.green;

else if (event.value=="3") event.target.fillColor = color.blue;

else if (event.value=="4") event.target.fillColor = ["RGB", 1, 1, 0]; // this is how you define a custom color, yellow in this case

else event.target.fillColor = color.white;