Skip to main content
Participant
May 24, 2022
Question

Help with Acrobat Javascript Shared Functions

  • May 24, 2022
  • 1 reply
  • 1396 views

This is not clear in the Javascript document, but where can I put shared functions which are used by my scripts?

Below I have 3 functions.  X() and Z() which should both happen on the blur of a text field.

Function Y() is a calculation which both X() and Z() need to use.

Y is available for X(), but not for Z() without pasting its code twice.

Where do shared functions go?

 

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------
 
 
//<AcroForm>
//<ACRO_source>CN1:Annot1:OnBlur:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:CN1:Annot1:OnBlur:Action1 ***********/
function X()
{
              int x = 0;
              //do something
              int y = Y();  //Works here
    return x;
}
 
function Y() 
{
              int y = 1;
              //do something
    return Y;
}
 
//</ACRO_script>
//</AcroForm>
 
 
//<AcroForm>
//<ACRO_source>CN2:Annot1:OnBlur:Action1</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:CN2:Annot1:OnBlur:Action1 ***********/
 
function Z() 
{
              int Z = 2;
              //do something
              int y = Y(); //Function Y is out of scope/unavailable here
    return Z;
}
 
//</ACRO_script>
//</AcroForm>

 

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
May 24, 2022

As doc-level scripts, under Tools - JavaScript - Document JavaScripts.

And do NOT edit the code via the Edit All JavaScripts command!

Participant
May 24, 2022

Ok??? so I added a document level script, and now all my onblur scripts are missing?

What the heck?

They still function but the All Javascripts only shows my document level script now, where are my actions??

 

Participant
May 24, 2022

Did you edit the code using Edit All Javascripts at any point?


I've been editing the code using the all scripts for the last year, havent had a problem until I added this document level script.

 

I have a form with 60 fields each with their on blur script.  Moving between each textbox to edit the script with a thousand menu clicks is absurd.  How else would I do this?