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

Changing colour and locking text fields by clicking check box

Explorer ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

Hi all

 

In interactive pdf forms is it possible to fill color in individual text fields basis certain criteria.  For example i have a text field which automatically fills a number basis conditions in a checkbox.

now i want this field to change colour also at the same time.  For better understanding please see below:

 

Text field - Score1

check box1

 

 

for now i have set the below script to get the desired value in Text field Score1 when the check box is clicked

 

if (event.target.value != "Off") {
this.getField("Score1").value = "60" ;
} else {
this.getField("Score1").value = "50" ;

now I want the text field to change colour to Red if i get 50 and to green if i get 60

please note that it is important that Text field Score1 is made non editable and change in colour stays permanent.

thanks for your help 

 

TOPICS
Acrobat SDK and JavaScript

Views

943

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 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

if (event.target.value != "Off") {
this.getField("Score1").value = "60" ;
this.getField("Score1").fillColor = color.green; } else { this.getField("Score1").value = "50" ;
this.getField("Score1").fillColor = color.red;
}

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
Explorer ,
Jun 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

Thanks a lot for your response, much appreciate.  I have tried this code but the challenge is that if i click on the text box (Score1) color changes as scripted however if I click anywhere else, colour disappears.  Also is there a way to make this text box uneditable as i do not want the user to change the values.  Thanks for all your help. 

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 19, 2020 Jun 19, 2020

Copy link to clipboard

Copied

Set the text field as read-only.

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
Explorer ,
Jun 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

Hi Many thanks for your response.  Can you please guide where is the read only tab as i can locate only locked option in the properties menu of the text field. ( which actually does not solve the purpose).

also seeking inputs on the colour change of the text fields.

thanks a lot for all your help.

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 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

The read-only property is under the General tab of the Properties dialog:

 

try67_0-1592641577026.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
Explorer ,
Jun 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

Thanks a lot Try67....found it...alls this while it was right in front of my eyes and didn't notice...thanks a lot!!!

 

One more question...

 

If in the text field i want to change the colour basis values obatined, what will be the code:

Example

I want Score1 text field colour to change to green if i get a value of .89 and above

Score 1 text fiel colour to change to yellow if the value is between ..6 to .89

and score 1 text field colour to change to red if value is less than .6

 

Thanks a lot for all your help....really appreciate

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 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

Do you have a calculation script for this field?

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
Explorer ,
Jun 21, 2020 Jun 21, 2020

Copy link to clipboard

Copied

Hi

i have used sum function from calculate field in the properties.  Basically this value is sum of around 10 text fields.

i do not have the script for the conditions to change colour.

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 21, 2020 Jun 21, 2020

Copy link to clipboard

Copied

As the custom validation script of the field you can use something like this:

if (event.value>=0.89) event.target.fillColor = color.green;

else if (event.value>=0.6) event.target.fillColor = color.yellow;

else if (event.value<0.6) event.target.fillColor = color.red;

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
Explorer ,
Jun 22, 2020 Jun 22, 2020

Copy link to clipboard

Copied

Many thanks for your response, much appreciate.  PLease note that i have tried to use the above scipt however it does not change anything.  Can you please help me iwth this.  I have changed some values and below is the condition.

 

Text field is called "Field1"

If calculated score is above 25.92 text Field1 should become green

If caluclated score is between 22.07 and 25.92 Field1 should become Yellow

and if calculated score is below 22.07, Field1 should become Red

 

Not sure why when i apply the script that you have shared the field always stay red. 

I have sued the below formula to calculate the score.

 

Many thanks for all your help.

 

 

score1.JPGscore2.JPG

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 22, 2020 Jun 22, 2020

Copy link to clipboard

Copied

You just need to plug in those new values into the code I provided. If that doesn't work share the file with us, please.

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
Explorer ,
Jun 23, 2020 Jun 23, 2020

Copy link to clipboard

Copied

My bad, had to put it as validation script.

It works like charm try67.  You are a genius. 🙂

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
Explorer ,
Jul 03, 2020 Jul 03, 2020

Copy link to clipboard

Copied

LATEST

I have one more question on this topic.  Is there a way to make a text box change colour basis a combination of there other text box colours.

 

Now that above script works like a charm and i can get the desired colour in the text field dependent on values.

now i want to change the colour of a text field basis the output colour of these text fields.

 

For example

Text field 1 has above validation script and changes colour basis value

Text field 2 has above validation script and changes colour basis value

Text field 3has above validation script and changes colour basis value

 

i want text field 4 to change colour if suppose:

 

Text field 1= Red

Text field 2= Green

Text field 3 = Yellow

 

final text field 4 becomes Yellow

 

else

 

Text field 1= Red

Text field 2= Red

Text field 3 = Yellow

 

Text field 4 = Red 

 

else

and so on.....

will highly appreciate your help in this

 

 

 

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