24 Replies Latest reply on Nov 3, 2011 9:28 AM by Choco_123

# Working with percentages in Adobe Acrobat 9 Pro

So, I have a quick question. I am new to working with forms in acrobat, and am having a hard time figuring this part out. If anyone can help me, I would greatly appreciate it!

So I have a form that I've created in acrobat 9 pro. Below I have listed "individual 1:" and then "percentage allocation". The "percentage alloctions" are the different form fields for the percentages I've created. For each form field, I limited the values to not exceed 100%. I want individuals filling in this form to be able to fill in the percentages by each of the names without the TOTAL percentage value (of all three together) going over 100%. But...the trick is, I don't have a separate "Total" form field, there's no room for one. So is there a way to make it so the total of the three equals 100% without having a "total" form field?

individaul 1:  percentage allocation

Individual 2: percentage allocation1

Individual 3: percentage allocation2

Please let me know if this makes sense,

• ###### 1. Re: Working with percentages in Adobe Acrobat 9 Pro

It's not very clear how you want it to work. Do you want the fields to automatically change their values if the total is bigger than 100%? If so, in what way?

Or do you just want to inform the user that the total is bigger than 100%?

• ###### 2. Re: Working with percentages in Adobe Acrobat 9 Pro

Hmm, sorry, I know I'm not very good at explaining it. So each line has it's own restriction in terms of value inputted. You can only put in numbers up to 100%. So, individual #1 can only input a number up to 100, same for individual 2 and 3.

So, if we work with actual values, let's say individual #1 puts in 50%,

individual 2 puts in 25%,

then the last individual should put in 25%( if we want the total to equal 100%). But let's just say they don't put in 25%  but put in 60% instead, which is way over 100%. I want to limit it so that the total percentages of all three equals 100%. Is there a way to do that?

• ###### 3. Re: Working with percentages in Adobe Acrobat 9 Pro

Are those fields set up as percentage fields or as number fields?

• ###### 4. Re: Working with percentages in Adobe Acrobat 9 Pro

I had set them up as percentage fields, but then changed it because it wouldn't let me just fill in values (like 50) without putting in decimals which would be confusing for the person filling it in, so I just changed it to numbers.

• ###### 5. Re: Working with percentages in Adobe Acrobat 9 Pro

In that case, let's say the fields are named "Individual1" to ""Individual3". You can use this code as the validate event of ""Individual1" (just adjust the names of the fields in the first line to use it in the other fields):

var total = Number(getField("Individual2").value) + Number(getField("Individual3").value) + Number(event.value);

if (total>100) {

app.alert("The total of the individual fields can't exceed 100%");

event.rc = false;

}

• ###### 6. Re: Working with percentages in Adobe Acrobat 9 Pro

You are a genius, thank you sooo much!!! I wouldn't have been able to figure that out on my own, I really appreciate it!

I have one other question, let's say I wanted to have "Individual 3"'s percentage filled in automatically based on what the user has filled in for the first two values, is that possible?

• ###### 7. Re: Working with percentages in Adobe Acrobat 9 Pro

Sure. Set it to be read-only, and use this code as the custom calculation script:

event.value = 100 - (Number(getField("Individual1").value) + Number(getField("Individual2").value));

• ###### 8. Re: Working with percentages in Adobe Acrobat 9 Pro

hmm, that one didn't work as well. When I cleared the form to try it, Individual 3's field is automatically filled in with a 100% value, and when I try to add anything in Individual 1 and 2, it gives me the error message of " individual fields can't exceed 100%"?

• ###### 9. Re: Working with percentages in Adobe Acrobat 9 Pro

Well, you have to remove the validation fields from the other fields... or

at least change them because it's a different situation.

• ###### 10. Re: Working with percentages in Adobe Acrobat 9 Pro

okay...thank you sooo much!

• ###### 11. Re: Working with percentages in Adobe Acrobat 9 Pro

Hey there,

I hope you don't mind, I have one more question, if you're willing to answer it for me.    This script allows for an error message to appear if the value is over 100%, which is great.

var total = Number(getField("Individual2").value) + Number(getField("Individual3").value) + Number(event.value);

if (total>100) {

app.alert("The total of the individual fields can't exceed 100%");

event.rc = false;

}

What if I want to add that I don't want the percentage to be lower than 100% either, because it needs to equal 100%. Is there a way of writing that into this script? Maybe another error message if the amount is lower than 100%?

• ###### 12. Re: Working with percentages in Adobe Acrobat 9 Pro

It's possible to do that, but I would reconsider it. The user will receive

this error message each time they change the value of a field (before they

change the other value), which can be quite annoying.

If you do want to implement it, it's basically the exact same code, just

change the larger -than symbol (>) to smaller-than (<).

• ###### 13. Re: Working with percentages in Adobe Acrobat 9 Pro

Yup, I just realized that when I changed the symbol the other way.   So I changed the setup from before. I ended up adding a Total field so that all the percentages would just add up there, so now it looks like this:

Individual 1:   %

Individual 2:  %

Individual 3:  %

Total:           %

and I modified the script to this:

var total = Number(getField("individual1").value) + Number(getField("individual2").value) + Number(getField("individual3").value);

if (total>100) {

app.alert("The total of the individual fields must equal 100%");

event.rc = false;

}

Is there anything else you can recommend or is this basically my option?

• ###### 14. Re: Working with percentages in Adobe Acrobat 9 Pro

I'm not clear on what it is you want to achieve now... Do you want to

prevent the user from entering a value if the total is bigger than 100? Do

you want just to warn them?

• ###### 15. Re: Working with percentages in Adobe Acrobat 9 Pro

These "individuals" are beneficiaries, and the percentages are the amounts that are allocated to each beneficiary. For each individual beneficiary, I have limited the field value from 0-100 so if anyone fills in over 100% for any of the beneficiaries, they will get an error message.

Then, for the total percentage, I added the script you sent me with my modifications. Right now the script works great and an error message comes up if the total goes over 100% after all the individual beneficiary amounts are added. But, let's just say this happens;

Individual 1: 30

Individual 2: 20

Individual 3: 10

Total:  60%

No error message or anything if the amount is lower than 100%.  I thought it would be okay if an error message comes up if the total is less than 100%, but you're right, that would get annoying for someone if they haven't filled in all the fields yet, and this error message keeps coming up. I guess I'm not sure what my options are unless I put in a disclaimer beside the total saying that the percentage needs to equal 100%?  I can't seem to think of any other solutions...

• ###### 16. Re: Working with percentages in Adobe Acrobat 9 Pro

There are several options. You can add a validation script that checks if

all 3 fields are filled-in, and if so displays the error message (if the

sum is smaller than 100). That would be less annoying...

Another option is the disclaimer text you've mentioned. You can even place

it as a hidden text field next to the total field that gets displayed if

the total is smaller than 100.

• ###### 17. Re: Working with percentages in Adobe Acrobat 9 Pro

Yes, those sound good, thank you so much. I've been looking at this too long and was out of ideas!  Maybe the second option would work better because there is a possibility that there is only one or two beneficiares, not all three, and it'll cut down on all the error messages. I will try it today and see if I can make it work! I really appreciate your help, and I thank you for taking the time to help me, especially with all my annoying questions!  Thanks again!

• ###### 18. Re: Working with percentages in Adobe Acrobat 9 Pro

Figured out how to hide the text box..no clue how to make it visible if the number falls below 100. I'm a designer, and have no clue about javascript. Is there anywhere I can go to figure out how to put the codes together so I don't keep bugging you?

• ###### 19. Re: Working with percentages in Adobe Acrobat 9 Pro

You really can't do anything without having the Acrobat JavaScript

Reference, which is available here:

The very latest of the reference (version 10) is inside the Acrobat X SDK

package.

To make a field visible or hidden you need to change the value of its

display property.

this.getField("Text1").display = display.visible; // make a field visible

this.getField("Text1").display = display.hidden; // make a field hidden

• ###### 20. Re: Working with percentages in Adobe Acrobat 9 Pro

But...the trick is, I don't have a separate "Total" form field, there's no room for one

if its easier to have a "total" form field, create one anywhere and just hide it (properties) ...

G

• ###### 21. Re: Working with percentages in Adobe Acrobat 9 Pro

Try67,

Thank you for sending me that reference guide, that will help. This is extremely frustrating for me. Thank you for the field visible or hidden script...I did end up finding those yesterday, just didn't know how to incorporate them to become visible if the total number is less than 100.

I ended up creating another text field right next to the total, and called it "statement". I marked this field as "hidden" through the general properties option in the adobe acrobat dialog box. And , I set up default text to read, "Total value must not be less than 100%". All of this, I did through the properties dialog box.

Individual 1: 30

Individual 2: 20

Individual 3: 10

Total:  60%             "statement" text field is here.

I figured what I could do is add another "if statement" to the validation script I put in for the "Total" text field I already had (below)..don't know if that was a stupid thing to do or not, but didn't know how else to do it. And where it says getField, I added the "statement" text field (the one that is hidden), thinking it would just get that field, but it's not working, what did I do wrong?

var total = Number(getField("individual1").value) + Number(getField("individual2").value) + Number(getField("individual3").value);

if (total>100) {

app.alert("The total of the beneficiary fields must equal 100%");

event.rc = false;

if (total<100) {

this.getField("statement").display = display.visible;

}

}

• ###### 22. Re: Working with percentages in Adobe Acrobat 9 Pro

Thanks Grant,

I did end up adding a total form field.

• ###### 23. Re: Working with percentages in Adobe Acrobat 9 Pro

Your statements are not nested properly. It should be:

var total = Number(getField("individual1").value) + Number(getField("individual2").value) + Number(getField("individual3").value);

if (total>100) {

app.alert("The total of the beneficiary fields must equal 100%");

event.rc = false;

} else if (total<100) {

this.getField("statement").display = display.visible;

} else if (total==100) {

this.getField("statement").display = display.hidden;

}

• ###### 24. Re: Working with percentages in Adobe Acrobat 9 Pro

It worked, thank you thank you thank you!!!!!!