Dropdown value isn't giving current selection

New Here ,
Jan 26, 2018 Jan 26, 2018

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?

TOPICS
Acrobat SDK and JavaScript

Views

105

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Jan 26, 2018 Jan 26, 2018
Do not use the calculate event. This is not a good idea. Listen to Try67Read 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

Likes

Translate

Translate
New Here ,
Jan 26, 2018 Jan 26, 2018

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 26, 2018 Jan 26, 2018

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>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 26, 2018 Jan 26, 2018

Copy link to clipboard

Copied

LATEST

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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines