Skip to main content
Known Participant
June 19, 2020
Question

Changing colour and locking text fields by clicking check box

  • June 19, 2020
  • 1 reply
  • 1939 views

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 

 

This topic has been closed for replies.

1 reply

JR Boulay
Community Expert
June 19, 2020
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;
}
Acrobate du PDF, InDesigner et Photoshopographe
NKB0609Author
Known Participant
June 19, 2020

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. 

NKB0609Author
Known Participant
June 22, 2020

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;


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.