## Calculation with Minimum Value

New Here ,
Nov 29, 2018

Copied

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;

}

}

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;`
TOPICS
Acrobat SDK and JavaScript, Windows

Views

92

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more ## Calculation with Minimum Value

New Here ,
Nov 29, 2018

Copied

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;

}

}

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;`
TOPICS
Acrobat SDK and JavaScript, Windows

Views

93

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more Nov 29, 2018 0
Most Valuable Participant ,
Nov 29, 2018

Copied

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

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more Nov 29, 2018 1
Most Valuable Participant ,
Nov 29, 2018

Copied

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;`

Likes

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more Nov 29, 2018 0