Skip to main content
Inspiring
June 3, 2020
Answered

About function in document-level JavaScript.

  • June 3, 2020
  • 1 reply
  • 1266 views

There is a data list of 20 columns in the form. Initially I was writing the following code in all 20 fields. This was working as planned.

 

var x = event.target.name;
var i = x.slice(4);
var CheckA = this.getField("CheckA"+i);

if(CheckA.isBoxChecked(0)){event.value=1;}
             else{event.value=0;};

 

I created the following simple function in document-level JavaScript.

 

function CalA() {
var x = event.target.name;
var i = x.slice(4);
var CheckA = this.getField("CheckA"+i);

if(CheckA.isBoxChecked(0)){event.value=1;}
             else{event.value=0;};
}

 

And I tried to change the following code into 20 fields.

 

CalA();

 

There was no problem in the first field I changed. However, when I change the second field, debugging will start and the following display will appear.

 

TypeError: CalA is not a function
1:AcroForm:CalA1:Calculate
TypeError: CalA is not a function
1:AcroForm:CalA2:Calculate

 

What is happening and how can I resolve it?

This topic has been closed for replies.
Correct answer Thom Parker

There must be an error in the code that is keeping it from being defined.

Are there any errors reported in the Console Window (Ctrl-J)

 

I don't see any problems with your code, it should be working.  So is there anything else in the document level script?

Can you post the entire code you placed in the Document Script?

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
June 3, 2020

There must be an error in the code that is keeping it from being defined.

Are there any errors reported in the Console Window (Ctrl-J)

 

I don't see any problems with your code, it should be working.  So is there anything else in the document level script?

Can you post the entire code you placed in the Document Script?

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
June 5, 2020

Thank you for your reply.  Unfortunately your advice probably doesn't seem to apply to my case.  Because I haven't use any other document level code.  Other comments do not appear in the console.

Inspiring
June 5, 2020

I have solved this problem just now. Thank you. There was a hint in your comment.

I was writing the following code in other Fields.

 

 

 

var x = event.target.name;
var i = x.slice(4);

var CalA = this.getField("CalA"+i);
var CalB = this.getField("CalB"+(i-1));

event.value = CalA.value + CalB.value;

 

 

 

I tried changing the function name of the code (function) I asked.  Then the problem did not occur.