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

Calculation with Minimum Value

New Here ,
Nov 29, 2018 Nov 29, 2018

How do I write a custom calculation for:

Text1 + Text2 + Text3 = Text20

If sum is 0 then value is 0

If sum is any number between 1 - 300 then value is 300

If sum is >300 then value is sum

Here is what is NOT working:

if( Text20 <= 300 ) {

event.value = 300; // value is 300 when sum is less than or equal to 300;

} else {

if ( Text20 == 0 ) {

event.value == 0; // value is 0 when sum is equal to 0;

} else {

event.value = Text20; // else value is the sum;

}

}

TOPICS
Acrobat SDK and JavaScript , Windows
426
Translate
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 , Nov 29, 2018 Nov 29, 2018

Use this code as the custom calculation script of your field:

var total = Number(this.getField("Text1").valueAsString) + Number(this.getField("Text2").valueAsString) + Number(this.getField("Text3").valueAsString);

if (total>1 && total<300) total = 300;

event.value = total;

Translate
LEGEND ,
Nov 29, 2018 Nov 29, 2018

Looks about right, except you are missing the compulsory "getField" call.

Translate
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
Community Expert ,
Nov 29, 2018 Nov 29, 2018
LATEST

Use this code as the custom calculation script of your field:

var total = Number(this.getField("Text1").valueAsString) + Number(this.getField("Text2").valueAsString) + Number(this.getField("Text3").valueAsString);

if (total>1 && total<300) total = 300;

event.value = total;

Translate
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