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

If Else statement and calculations within statement

Community Beginner ,
Feb 10, 2023 Feb 10, 2023

Copy link to clipboard

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)

 

 

Thank you for any help you can give.

 

Nancy

TOPICS
How to , JavaScript , PDF forms

Views

282

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 , 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;
     app.alert("Amount is over 6x your salary. You can't have it");
}

 

Votes

Translate

Translate
Community Expert ,
Feb 10, 2023 Feb 10, 2023

Copy link to clipboard

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;
     app.alert("Amount is over 6x your salary. You can't have it");
}

 

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

Copy link to clipboard

Copied

LATEST

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

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