Skip to main content
cmvarga5
Known Participant
June 5, 2025
Answered

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

  • June 5, 2025
  • 1 reply
  • 302 views

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.

Correct answer Thom Parker

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.  

 

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
June 5, 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 PDFScriptingUse the Acrobat JavaScript Reference early and often
cmvarga5
cmvarga5Author
Known Participant
June 6, 2025

WOW! That works!  Thank you so much!