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

Custom Validation Script help if/then

New Here ,
Oct 27, 2023 Oct 27, 2023

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!

TOPICS
How to , JavaScript , PDF forms
664
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 ,
Oct 27, 2023 Oct 27, 2023

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

 

 

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

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
New Here ,
Oct 30, 2023 Oct 30, 2023

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. 

 

Elisa33220775agv0_0-1698688298872.pngexpand image

 

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 ,
Oct 30, 2023 Oct 30, 2023
LATEST

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 = "";

 

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

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