Skip to main content
New Participant
June 18, 2024
Answered

Calculated field should total 100%

  • June 18, 2024
  • 1 reply
  • 1075 views

Hi all,
I am creating a fillable pdf with some calculated fields.
For one in particular I would like the sum of 3 previous percentage fields to total 100%, and if the total is
< or > 100, I would like an error message that says something like "this total should equal 100%"

 

The 3 percentage fields included in the calculation should be allowed to be blank, or have a number from 0-100 entered.

I tried just adding a validation to the calculated field of "between 100 and 100", but this gets applied to the the previous 3 percentage fields included in the calculation which is not what I want.

Any help would be incredibly helpful!

 

This topic has been closed for replies.
Correct answer PDF Automation Station

Another idea is to change the color of the field and text until the correct total is reach.  For example:  Red text on yellow background, then once the value is 100%, black text on transparent background.

1 reply

PDF Automation Station
Community Expert
June 18, 2024

Enter the following custom calculation script in the Total field, assuming the other 3 fields are named Field1, Field2, and Field3.

 

var field1=this.getField("Field1").value;
var field2=this.getField("Field2").value;
var field3=this.getField("Field3").value;


if(field1!=="" && field2!=="" && field3!=="")
{
event.value=field1+field2+field3;
if(event.value!=1)
{
app.alert("The total must equal 100%",1);
event.value="";
}
}

 

The calculation only runs when all three fields have a value including zero (but not blank), otherwise the alert will pop every time any field value changes, until all three add up to 1 (100%).  The form should have instructions to enter 0 if the percentage is zero.

try67
Community Expert
June 18, 2024

I recommend using a different way of notifying the user of the issue. An alert will be extremely annoying to them.

Use a (read-only) text field for it, or even just populate the field itself with the alert, alongside (or instead of) the total value.

New Participant
July 10, 2024

Thanks, yeah, alerts can definitely get annoying...
I think we've decided on prepopulating the field with 100 so people can see they're supposed to add up to 100, and then the calculation kicks in once they enter percentages.

Thanks so much for your time in responding!