Copy link to clipboard
Copied
Hi everyone
Hoping one of you can help me please....
I have a pdf doc which is a questionnaire with a drop down list of responses for each answer (Yes, No and Partly). I then have a summary page at the end which counts the number of answers and calculates the percentage against each answer, i.e. Yes 34% No 23% Partly 43% ( i have a field for each of these). What I would now like to do is have a field which calculates the largest percentage and fills the field with colour depending on the largest percentage, i.e if Yes is largest percentage then field is filled with Green, No with Red and Partly with yellow.
can someone help me with the script for this please?
Thank you so much in advance!!!
OK, then you can use this code as the custom calculation script of your field:
...var newFillColor = color.transparent;
var values = [Number(this.getField("D1Yes%age").valueAsString), Number(this.getField("D1No%age").valueAsString), Number(this.getField("D1Partly%age").valueAsString)];
var colors = [color.green, color.red, color.yellow];
var max = 0;
for (var i in values) {
if (values>max) {
max = values;
newFillColor = colors;
}
}
event.value = max;
event.target.fillColor = newFillColo
Copy link to clipboard
Copied
So you already have a script that calculates the percentage of each answer? If so, what are the names of those fields?
Copy link to clipboard
Copied
Yes I do - those fields are called D1Yes%age, D1No%age and D1Partly%age
Thank you!!!
Copy link to clipboard
Copied
OK, then you can use this code as the custom calculation script of your field:
var newFillColor = color.transparent;
var values = [Number(this.getField("D1Yes%age").valueAsString), Number(this.getField("D1No%age").valueAsString), Number(this.getField("D1Partly%age").valueAsString)];
var colors = [color.green, color.red, color.yellow];
var max = 0;
for (var i in values) {
if (values>max) {
max = values;
newFillColor = colors;
}
}
event.value = max;
event.target.fillColor = newFillColor;
Copy link to clipboard
Copied
This works perfectly for the colour - thank you so much! But it returns a number in the field also. How can I get this to just be colour filled with no text?
Copy link to clipboard
Copied
Sorry, thought you wanted to display the actual max value as well. Just remove line #11 from the code above.
Copy link to clipboard
Copied
(and clear the field)
Copy link to clipboard
Copied
THANK YOU SO MUCH!!!! I am so grateful!! That's perfect!!!