• Global community
• Language:
• Deutsch
• English
• Español
• Français
• Português
• 日本語コミュニティ
Dedicated community for Japanese speakers
• 한국 커뮤니티
Dedicated community for Korean speakers
Exit Search
• If Else statement and calculations within statemen...

# If Else statement and calculations within statement

Community Beginner ,
Feb 10, 2023 Feb 10, 2023

Copied

All, I currently have a drop down list for Amount of life insurance the customer wants to purchase called "EEVLife" and a second calculated field that calculates the cost per paycheck based on the amount of insurance and their current age.  I have a third requirement to be able to be sure they can order that much life insurance and it is that they cannot purchase more than 6x their field "AnnualSalary".

This is my current code.  Where do I put the qualification for the Annual Salary and how do I code it?

var age=Number(this.getField("CalculatedAge").valueAsString);
var rate=0
if (age<30) rate=0.13;
else if (age<=34) rate=0.14;
else if (age<=39) rate=0.17;
else if (age<=44) rate=0.23;
else if (age<=49) rate=0.32;
else if (age<=54) rate=0.52;
else if (age<=59) rate=0.79;
else if (age<=64) rate=1.00;
else if (age<=69) rate=1.75;
else if (age<=74) rate=3.79;
else if (age>=75) rate=10.03;

event.value=((((this.getField("EEVLife").value/1000)*rate)*12)/26)

Nancy

TOPICS
How to , JavaScript , PDF forms

Views

73

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 Expert , Feb 10, 2023 Feb 10, 2023

Put the script for testing the calculated amount into the custom Validation Script for the field where this calculation is happening.

``````var nMaxAmt =  this.getField("AnnualSalary").value * 6;
if(event.value > nMaxAmt)
{
event.rc = false;
}``````

2 Replies 2
Community Expert ,
Feb 10, 2023 Feb 10, 2023

Copied

Put the script for testing the calculated amount into the custom Validation Script for the field where this calculation is happening.

``````var nMaxAmt =  this.getField("AnnualSalary").value * 6;
if(event.value > nMaxAmt)
{
event.rc = false;
}``````

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
Feb 10, 2023 Feb 10, 2023

Copied

LATEST

You are the bomb!!! Worked perfectly!  Thank you

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Resources