Copy link to clipboard
Copied
Hi everybody,
I want to set up a form in which depending if 3 of the criteria are answered with a dropdown "Yes", a text field is filled with a corresponding color and/or text, indicating that all criteria are met (or not).
Example:
I have been playing around with various Javascripts I found in the forums, but none really seemed to work.
Do you have any suggestions on how I could solve this? Or how I could at leaset get the answers in the dropdown to change colour depending on the selected answer?
Thank you!
OK, then let's say they're called Dropdown1 to 3. Create a (read-only) text field with the following code as the custom calculation script to achieve what you described:
var score = 0;
for (var i=1; i<=3; i++) {
var f = this.getField("Dropdown"+i);
if (f.valueAsString=="Yes") score++;
}
if (score==0) event.target.fillColor = color.red;
else if (score<3) event.target.fillColor = ["RGB", 255/255, 191/255, 0/255];
else event.target.fillColor = color.green;
I would also recommend to set the o
...change: (score ==0) to: (score<=1)
Copy link to clipboard
Copied
So if all the fields are set to Yes it should be green, if any field is set to No it should be amber, and if all are set to No it should be red?
Also, in the screenshot your fields don't look like drop-downs. What actual fields are they?
Copy link to clipboard
Copied
So if all the fields are set to Yes it should be green, if any field is set to No it should be amber, and if all are set to No it should be red? // Exactly
Also, in the screenshot your fields don't look like drop-downs. What actual fields are they? // The screenshot is made in Excel just for demonstrations purposes. The fields would be Dropdown fields in Acrobat Pro
Copy link to clipboard
Copied
OK. Will the fields only have Yes and No as their options? There's no "blank" default option?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
OK, then let's say they're called Dropdown1 to 3. Create a (read-only) text field with the following code as the custom calculation script to achieve what you described:
var score = 0;
for (var i=1; i<=3; i++) {
var f = this.getField("Dropdown"+i);
if (f.valueAsString=="Yes") score++;
}
if (score==0) event.target.fillColor = color.red;
else if (score<3) event.target.fillColor = ["RGB", 255/255, 191/255, 0/255];
else event.target.fillColor = color.green;
I would also recommend to set the option to commit the selected value of the drop-down fields immediately, which can be found under their Properties, in the Options tab.
Copy link to clipboard
Copied
It works! Thank you so much!
Is it possible to also make the read-only text field which is now the "stoplight" show the colour without having to click on it? Because right now the box is grey/blue, and only "turns" green/orange/red when I click on it.
Copy link to clipboard
Copied
Disable the form fields highlighting.
Copy link to clipboard
Copied
This only works then for people who have this disabled in Adobe, correct?
Is there a way to set it for all people who receive the PDF?
Copy link to clipboard
Copied
Yes, but it will affect all other files they open, so you should at least inform them when you make this change.
In order to do it embed the following code in your file as a doc-level script:
app.runtimeHighlight = false;
Copy link to clipboard
Copied
All other files that they will ever open, or only the files that they open when this specific file of mine is already open?
Copy link to clipboard
Copied
All other files, unless you add another script to your file to set it back to its original state when they close it.
Copy link to clipboard
Copied
PS. This should not happen if you set the field as read-only, by the way. Have you done that?
Copy link to clipboard
Copied
Ah, I had ticked the wrong box - now it works without the extra script and settings in Adobe.
Thank you so much for your help!!!!
Copy link to clipboard
Copied
Hi, small question:
How should the Javascript be if I want the "stoplight" to turn red as well, as soon as two of three options is set to no? Currently it "only" turns red when all three options are no.
Thank you!
Copy link to clipboard
Copied
change: (score ==0) to: (score<=1)
Copy link to clipboard
Copied
Thank you!