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

Calculated field should total 100%

Community Beginner ,
Jun 17, 2024 Jun 17, 2024

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!

 

TOPICS
How to , JavaScript , PDF forms
1.1K
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
3 ACCEPTED SOLUTIONS
Community Expert ,
Jun 18, 2024 Jun 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.

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 Beginner ,
Jul 09, 2024 Jul 09, 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!

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 ,
Jul 09, 2024 Jul 09, 2024
LATEST

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.

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 17, 2024 Jun 17, 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.

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 18, 2024 Jun 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.

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 Beginner ,
Jul 09, 2024 Jul 09, 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!

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 Beginner ,
Jul 09, 2024 Jul 09, 2024

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!

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 ,
Jul 09, 2024 Jul 09, 2024
LATEST

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.

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