Custom Validation Script help if/then
Copy link to clipboard
Copied
I am creating a form that has dropdown items with numerical values to be selected and then a cumulative score field that adds up each dropdown field. This works fine. However, I am now trying to add an additional field that looks at the Cumulative total to determing if the cumulative value is between two numbers then it returns a specific value. Example: Cumulative Total = 33, If the Cumulative Total is between 28-38, then return value = 3 in the box. I have 6 sets of values the cumulative total would compare to in order to return a value of 0 - 5, respectively. I am completely new to writing these types of scripts and any help would be appreciated!
Copy link to clipboard
Copied
If the Cumulative Total calculation is a script, then add the code for setting the "box" value in this script.
Otherwise, you could use a Custom Validation script on the Cumulative Total field.
Here's an example:
var oBoxFld = this.getField("box");
if((event.value >=28) && (event.value < 38))
oBoxFld.value = 3;
else if((event.value >=38) && (event.value < 48))
oBoxFld.value = 4;
else
oBoxFld.value = "";
Just follow the pattern to fill out all the conditions.
You can read all about "if/then" statments here:
https://www.pdfscripting.com/public/How-to-write-an-If-statement.cfm
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
The Cumulative Score field is a calculation script to add 11 fields together. That calculation works. I've tried copying the above and putting it into the validation script but nothing populates when I test.
Copy link to clipboard
Copied
So there are a few issues, mainly that the script needs to be placed in the correct location, and reference the correct field.
For example, the calculation is in the "CumulativeScore" field. So the validation script can't set that value, cause it's already calculated.
I believe that it is the "Overall Rating" field that you want to set? These are the kind of details you need to tell us, cause you know, we can't read minds.
So put this script in the Custom Validation for the "CumulativeScore" field.
// This script goes in the validation for the "CumulativeScore" field.
var oBoxFld = this.getField("Overall Rating");
if((event.value >=28) && (event.value < 38))
oBoxFld.value = 3;
else if((event.value >=38) && (event.value < 48))
oBoxFld.value = 4;
else
oBoxFld.value = "";
Use the Acrobat JavaScript Reference early and often

