Copy link to clipboard
Copied
I am trying to write a script to change a dropdown's background color depending on the value selected. I have "Commit selected value immediately" selected and my code, which is attached to Validate is here:
var drop = this.getField("Dropdown1");
var DropDownValue = event.value;
DropDownValue = drop.value;
console.println(DropDownValue);
if (DropDownValue == "Pass"){
DropDown.fillColor = color.green;
}else if(DropDownValue == "Fail"){
DropDown.fillColor = color.red;
}else{
DropDown.fillColor = color.white;
}
The problem I am having is when I select "Pass" it doesn't change, but when I select "Fail", "Pass" gets written to the console and the dropdown turns green as if I selected "Pass". Then when I select "Pass" again "Fail" gets written to the console and it turns red. Basically Adobe thinks the prior selection is the current one. How can I fix this behavior?
Do not use the calculate event. This is not a good idea. Listen to Try67
Read these articles on DropDowns.
This one discuses changing another field, but the same technique (simplified) could be used to change the field color.
https://acrobatusers.com/tutorials/change_another_field
This one just discusses the basics for programming dropdowns in Acrobat
https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm
Copy link to clipboard
Copied
I was able to fix this by putting the script in the "Calculate" tab, even though nothing is calculated. I would still like to know why Adobe is getting an old event though
Copy link to clipboard
Copied
Because the value is not yet committed to the field at that point. To
access the new value (in either one of these events), use event.value
instead of this.getField("").value.
On 26 January 2018 at 18:57, joshual57966311 <forums_noreply@adobe.com>
Copy link to clipboard
Copied
Do not use the calculate event. This is not a good idea. Listen to Try67
Read these articles on DropDowns.
This one discuses changing another field, but the same technique (simplified) could be used to change the field color.
https://acrobatusers.com/tutorials/change_another_field
This one just discusses the basics for programming dropdowns in Acrobat
https://www.pdfscripting.com/public/List-Field-Usage-and-Handling.cfm