• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Changing field background colour on click or inserting a letter

New Here ,
Jun 11, 2024 Jun 11, 2024

Copy link to clipboard

Copied

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.

TOPICS
Create PDFs , Edit and convert PDFs , PDF , PDF forms

Views

187

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 11, 2024 Jun 11, 2024

Copy link to clipboard

Copied

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 11, 2024 Jun 11, 2024

Copy link to clipboard

Copied

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

Screenshot 2024-06-11 at 21.28.20.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 11, 2024 Jun 11, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 12, 2024 Jun 12, 2024

Copy link to clipboard

Copied

Do those squares need letters in them, or do you simply need to change the colors?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 12, 2024 Jun 12, 2024

Copy link to clipboard

Copied

I simply need to be able to change each little square ti either red, yello, green or blue 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 12, 2024 Jun 12, 2024

Copy link to clipboard

Copied

1)  Create a tranparent button where the top left square is and enter the following script as a mouse up action:

change_Color(event.target);

2)  Right click the field and selection Create Multiple Copies...

3)  Enter 30 down and 33 across and click OK.

4)  Enter the following document level script:

function change_Color(fld)
{
if(ColorEqual(fld.fillColor,color.transparent))
{fld.fillColor=color.red}
else if(ColorEqual(fld.fillColor,color.red))
{fld.fillColor=color.yellow}
else if(ColorEqual(fld.fillColor,color.yellow))
{fld.fillColor=color.green}
else if(ColorEqual(fld.fillColor,color.green))
{fld.fillColor=color.blue}
else if(ColorEqual(fld.fillColor,color.blue))
{fld.fillColor=color.transparent}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 12, 2024 Jun 12, 2024

Copy link to clipboard

Copied

Thanks so much for this.  I have tried but when I add then 30 down and 33 across duplicates and press ok I get the spinning wheel of doom and acrobat stops responding!  Any ideas around this.  Also if I get past that point, where & how do I add the document level script?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 12, 2024 Jun 12, 2024

Copy link to clipboard

Copied

I'm not sure why you're get the "spinning wheel of doom" (LOL).  Does it ever stop, or do you have to do a hard shutdown?  It is possible that you don't have enough room to do 30 down and 33 across (because it puts spaces between the rows and columns), but it should simply tell you that in a warning message instead of freezing on you.  It could also be that your document contains a lot of graphics, fields, etc.  The copy multiple fields function runs a lot of calculations for the positioning of the fields.  You could try doing this on a blank one-page PDF and then copying the fields over in mass.  Or you could try putting the button on the top left corner, copying from there, and moving the fields after.  If that doesn't work, try 9 rows of 9, then use one of those fields to create multiple copies again until you have enough.  The document level script window can be found by searching JavaScript in the Tools tab (new Acrobat disabled) and clicking Document JavaScripts.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 12, 2024 Jun 12, 2024

Copy link to clipboard

Copied

This has worked thank you so much!   Could you let me know how to save it as an interactive form that I can send to people to use themselves?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 12, 2024 Jun 12, 2024

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 12, 2024 Jun 12, 2024

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines