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. 

try67
Community Expert
June 21, 2020

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


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;