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

Form fields should all equal to 100% but there is no total field to calculate the sum

Explorer ,
Jun 05, 2025 Jun 05, 2025

I have 3 form fields with the 1234.56 format style applied to them. When entering numbers in these fields, they should all equal to 100. Is there a way to block the last form field from entering a number over the total?

 

Field 1__________

Field 2__________

Field 3__________

= 100.

 

There is no total amount form field to calculate the sum of those form fields. People can enter whatever number in the form fields, but there should be either a warning or automatically delete the last form field if they enter a number that will equal over 100.

TOPICS
How to , JavaScript , PDF , PDF forms , Standards and accessibility
120
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
1 ACCEPTED SOLUTION
Community Expert ,
Jun 05, 2025 Jun 05, 2025

So they are entering a percentage, such as 34.5 for 34.5%?  What happens if they enter a number >= 100?

What are the field names.

 

 

This is a bit tricky, but perhaps the best approach is to use Validation Scripts on each field. This will provide an opportunity to reject the entries on a field by field basis. 

 

// Validation script on Field 1
// First, reject numbers over 100
if(event.value > 100)
{
    event.rc = false;
    app.alert("Value must be 100% or less");
}
else
{// Test other fields.
    var nSum = Number(event.value) + Number(this.getField("Field2").value) + Number(this.getField("Field3").value);
    if(nSum > 100){
      event.rc = false;
      app.alert("The entry in this field brings the total to greater than 100%");
    }    
}

 

This could be generalized into a single validation script for all of the fields.  

 

 

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

View solution in original post

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 ,
Jun 05, 2025 Jun 05, 2025

So they are entering a percentage, such as 34.5 for 34.5%?  What happens if they enter a number >= 100?

What are the field names.

 

 

This is a bit tricky, but perhaps the best approach is to use Validation Scripts on each field. This will provide an opportunity to reject the entries on a field by field basis. 

 

// Validation script on Field 1
// First, reject numbers over 100
if(event.value > 100)
{
    event.rc = false;
    app.alert("Value must be 100% or less");
}
else
{// Test other fields.
    var nSum = Number(event.value) + Number(this.getField("Field2").value) + Number(this.getField("Field3").value);
    if(nSum > 100){
      event.rc = false;
      app.alert("The entry in this field brings the total to greater than 100%");
    }    
}

 

This could be generalized into a single validation script for all of the fields.  

 

 

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
Explorer ,
Jun 06, 2025 Jun 06, 2025
LATEST

WOW! That works!  Thank you so much!

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