Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Thank you so much - that's great!
A little worried about '0' needing to be entered, so I think I might just pre-populate the total field with 100 and then it disappears once they start entering percentages.
That app.alert is really helpful though, thank you so much for taking the time to respond!
Copy link to clipboard
Copied
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.