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

Validate only calculate if any of these fields have data

New Here ,
May 22, 2025 May 22, 2025

Long time user and forum follower. I've gotten help off here several times, but first time posting. We have a form in the Army to write up faults. I changed it to auto calculate money, manhours, etc. I've created it with 3 pages in case we have to write more stuff up. I have each totals calculating total from page 1 + total page 2 etc. Is there any way to validate the next page will only calculate if data is put in any of the fields on page 2? In other words no total will auto calculate on page 2 and page 3 unless a field is filled on page 2. Like if data is in "field1" or "field2" or "field3" etc then it'll begin calculating that page. Have attached screenshots of 2 of the pages. 

TOPICS
JavaScript
159
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 ,
May 22, 2025 May 22, 2025

You don't say what the field names are, how they differ from page to page, if at all, and what type of calculation you are using.  This might help you:

https://pdfautomationstation.substack.com/p/another-method-for-calculation-vs

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 ,
May 22, 2025 May 22, 2025

I stated I have the totals carrying down from page to page + whatever the totals are on that page. I attached pictures of the form and set examples of "field1" "field2" etc. I can change the names of the fields in the code. 

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 ,
May 22, 2025 May 22, 2025
LATEST

Yes.  The script in the calculations that need to be blocked can be setup to test for valid values in other fields before proceeding. 

 

For example, if the field that needs to be checked is named "Data1", then the calculation script that needs to be validated would look like this:

This code proceeds with the calculation only if the value in the Data1 fields is not empty and a number value. 

var strChkValue = this.getField("Data1").valueAsString;
if((strChkValue != "") && !isNaN(strChkValue)) 
{
   ... Do calculation.. 
   event.value = ...something...;
}

 

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