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

About function in document-level JavaScript.

Participant ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

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?

TOPICS
Acrobat SDK and JavaScript

Views

783

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 , Jun 03, 2020 Jun 03, 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?

 

Votes

Translate

Translate
Community Expert ,
Jun 03, 2020 Jun 03, 2020

Copy link to clipboard

Copied

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 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
Participant ,
Jun 04, 2020 Jun 04, 2020

Copy link to clipboard

Copied

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.

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
Participant ,
Jun 05, 2020 Jun 05, 2020

Copy link to clipboard

Copied

LATEST

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.  

 

 

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