Skip to main content
Participant
May 24, 2022
質問

Help with Acrobat Javascript Shared Functions

  • May 24, 2022
  • 返信数 1.
  • 1396 ビュー

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>

 

このトピックへの返信は締め切られました。

返信数 1

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??

 

try67
Community Expert
Community Expert
May 24, 2022

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?


It's possible the file got corrupted because of that. If so, there's no easy way to fix it.

If you have a n earlier version of it saved, revert to it and apply the scripts differently this time around.

That can also be done using a script, instead of manually.