Highlighted

About function in document-level JavaScript.

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

Adobe Community Professional
Correct answer by Thom_Parker | Adobe Community Professional

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?

 

Topics

Acrobat SDK and JavaScript, How to, PDF forms

Views

297

Likes

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

About function in document-level JavaScript.

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

Adobe Community Professional
Correct answer by Thom_Parker | Adobe Community Professional

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?

 

Topics

Acrobat SDK and JavaScript, How to, PDF forms

Views

298

Likes

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
Adobe Community Professional ,
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?

 

Likes

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
Reply
Loading...
Participant ,
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.

Likes

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

Copy link to clipboard

Copied

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.  

 

 

Likes

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
Reply
Loading...