• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

371

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

Community Expert , Jan 26, 2018 Jan 26, 2018

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

Votes

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

Votes

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
Community Expert ,
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>

Votes

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
Community Expert ,
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

Votes

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