Skip to main content
Participating Frequently
June 11, 2024
Answered

Changing field background colour on click or inserting a letter

  • June 11, 2024
  • 1 reply
  • 1431 views

Please help if you can.  I am creating a tracking tool pdf.  I want the user to be able to choose one of four colours for the background of a text field according to the level of their student.  Red = Emerging, Yellow = Developing, Green = Achieved, Blue = Greater Depth.  Is there a way that the field can change colour on clicking ie first click red, second click yellow, third click green and fourth click blue or by entering the relevant intial into the text field ie E = red, D = yellow, A = green and G = blue?  I have been struggling for days with this so any help would be hugely appreciated.

This topic has been closed for replies.
Correct answer try67

When I open it in adobe acrobat all of the buttons work but if I open in a different program they don't 

 


That's often the case. Most non-Adobe applications have very poor support for scripts, unfortunately.

1 reply

PDF Automation Station
Community Expert
Community Expert
June 11, 2024

A text field is not good for a mouse up action for multiple clicks because you have to blur out of the field to see the change.  A button field next to the text field would work better.  To use the first letters to change the color, enter the follow script as a custom format script:

 

 

var letter=event.value.split("")[0];
if(letter=="E"){event.target.fillColor=color.red}
else
if(letter=="D"){event.target.fillColor=color.yellow}
else
if(letter=="A"){event.target.fillColor=color.green}
else
if(letter=="G"){event.target.fillColor=color.blue}
else
{event.target.fillColor=color.transparent}

 

Leave the field to see the changes.  The letters are case sensitive.

 

Participating Frequently
June 11, 2024

I have lots of fields to change the colour of  (see pic below)  there are even more than this.  30 rows by 33 coloumns and I need to change each of the little grey squares into one of those four colours.  I wonder if you could let me know the easiest way to do this.  It's not practical to hava a button for each field. Thanks so much for your time

try67
Community Expert
Community Expert
June 11, 2024

There's no other way. You must create a separate field for each letter. But you can easily do it using the Create Multiple Copies command, after you've set up the first one.

 

What you should do, though, is place the code as a doc-level function and then just call it from each button. That way, if you wanted to make a change later on you would only need to do it in one place.