Currently Being Moderated

## Working with percentages in Adobe Acrobat 9 Pro

### Oct 31, 2011 1:12 PM

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,

Replies
• Currently Being Moderated
Oct 31, 2011 1:48 PM   in reply to Choco_123

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%?

|
Mark as:
• Currently Being Moderated
Oct 31, 2011 2:33 PM   in reply to Choco_123

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

|
Mark as:
• Currently Being Moderated
Oct 31, 2011 2:53 PM   in reply to Choco_123

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;

}

|
Mark as:
• Currently Being Moderated
Oct 31, 2011 3:18 PM   in reply to Choco_123

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));

|
Mark as:
• Currently Being Moderated
Oct 31, 2011 3:32 PM   in reply to Choco_123

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

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

|
Mark as:
• Currently Being Moderated
Nov 2, 2011 6:29 AM   in reply to Choco_123

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 (<).

|
Mark as:
• Currently Being Moderated
Nov 2, 2011 6:41 AM   in reply to Choco_123

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?

|
Mark as:
• Currently Being Moderated
Nov 2, 2011 6:57 AM   in reply to Choco_123

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.

|
Mark as:
• Currently Being Moderated
Nov 3, 2011 6:35 AM   in reply to Choco_123

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

|
Mark as:
• Currently Being Moderated
Nov 3, 2011 7:15 AM   in reply to Choco_123

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

|
Mark as:
• Currently Being Moderated
Nov 3, 2011 8:27 AM   in reply to Choco_123

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;

}

|
Mark as:
Actions

#### More Like This

• Retrieving data ...

#### Answers + Points = Status

• 10 points awarded for Correct Answers