Skip to main content
Known Participant
May 19, 2023
Answered

Document Javascript works in Acrobat, but not in Reader when called as a function from fields

  • May 19, 2023
  • 2 replies
  • 1541 views

I have a series of fields that are set to remain hidden until a particular calculating field's value goes above zero. I have a script at the document level that is called from the series of fields as a function in Custom calculation script (see below.) This works great in Acrobat but not in Reader. If I modify it where the script is directly in each field, it works in Reader. I use Adobe Acrobat 2020 and Adobe Acrobat DC Reader. I have attached the file.

 

function unhideFields() {

   var a = this.getField("txtAdjustmentAmt");
   var f = event.target;

   if (a.value > 0)  
   {
       f.display = display.visible;
   }
   else if (a.value <= 0)
   {
       f.display = display.hidden;
   }
}

Thank you,

 

Teagan

This topic has been closed for replies.
Correct answer Bernd Alheit

Check the Javascript console for errors. 

You will get an error message in Acrobat Reader at:

  this.setAction("WillClose", myWillClose);

And the function unhideFields will not defined.

 

2 replies

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
May 20, 2023

Check the Javascript console for errors. 

You will get an error message in Acrobat Reader at:

  this.setAction("WillClose", myWillClose);

And the function unhideFields will not defined.

 

try67
Community Expert
Community Expert
May 20, 2023

I was going to try and help you, but then you went and changed my default highlighting color to your own, without notifying me of the change or asking my permission for doing so, so now I'm not going to bother. I strongly recommend you don't do such things to your users!

CeltexanAuthor
Known Participant
May 23, 2023

My apologies, @try67. There are codes to change the highlight color at the opening and revert them to the original setting at closing. I have that set for all of the forms for the company color scheme, and I am sorry I did not think to remove it from the sample form I provided. If I remove the script for that and share it again, would you help?

try67
Community Expert
Community Expert
May 23, 2023

I apologize if I was a bit curt with you. I didn't notice you were reverting the highlight color at the end, and this practice really irks me.

At any rate, Bernd sent you on the right path. Since setAction can't be used in Reader it triggers an error and then the rest of the code doesn't execute, resulting in an error. You don't really need this command anyway. Just execute it once in the Console and save the file, and you're done. Remove it from the doc-level script and you'll see it works fine.