These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Percentage sum 4 fields

Tigerlady
Registered: Oct 31 2006
Posts: 20

I know this has probably been asked a thousand time but i am on a tight schedule and don't have time to read every post so please forgive me for asking again.

I have a form that has 4 fields.
they are all % the sum of those fields cannot be more than 100%

so here is what i have so far.

For Swipe field
under options:
default value: 100
limit of 3 characters
format: number
seperator 1234.56
validation: field value is in range 0 to 100

for MailOrder
Options
default value 0
limit of 3 characters
format: number
seperator 1234.56
validation: field value is in range 0 to 100

for eCommerce
Options
default value 0
limit of 3 characters
format: number
seperator 1234.56
validation: field value is in range 0 to 100

for Manual
Options
default value 0
limit of 3 characters
format: number
seperator 1234.56
validation: field value is in range 0 to 100

what i need to have happen is to make sure that the total of all the fields Sum to 100 and don't go over. can someone please give me instructions on how to accomplish this.

thanks.

Ms. Barbara S. ONeal
President/Co-Founder
Centric Web®, Inc.
630-734-0741
http://www.centricweb.com
Adobe Community Expert

My Product Information:
Acrobat Pro Extended 9.1.1, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You can make a total field and then write a 'custom calculation script' to compute the total and issue a message if the total is larger than 100.

var sum = 0; // sum of fieldsvar aFields = new Array("Swipe ", "MailOrder", "eCommerce", "Manual"); // array of field name to sum// sum the fieldsfor(i = 0, i < aFields.length; i++) {sum += Number(this.getField(aFields[i]).value); // add value as number}// test value of the sumif(sum > 100) {// sum greater than 100app.alert("Sum of sales fields can not exceed 100", 0, 1);}// fill in field valueevent.value = 100;

George Kaiser

Tigerlady
Registered: Oct 31 2006
Posts: 20
I tried the code you supplied. First I created a hidden field then using the validate tab set it ti use custom Javascript. below is the code that i am trying to use. however when i enter it into the editor box i get an error in the javascript pop up.

Quote:
missing ; after for-loop condition
3: at line 4
I have tried various things but am still so lost


var sum = 0;var aFields = new Array("POB_Card_Swipe", "POB_ECommerce", "POB_Mail_Order_Telephone", "POB_Manual");for(i = 0, i < aFields.length; i++) {sum += Number(this.getField(aFields[i]).value);}if(sum > 100) {app.alert("Sum of sales fields can not exceed 100", 0, 1);}event.value = 100;

Ms. Barbara S. ONeal
President/Co-Founder
Centric Web®, Inc.
630-734-0741
http://www.centricweb.com
Adobe Community Expert

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You should have paid more attention to the error message you got. In line 3, replace this:
for(i = 0,
with this:
for(i = 0;

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Tigerlady
Registered: Oct 31 2006
Posts: 20
Darn missed that.

Ok I no longer have the error however, it doesn't work or throw an error when i try to fill the fields to total more than 100%. I have turned the field to visible for now and it doesn't pick up the totals and yes i have made sure that all the field names are correct. Am i still missing something?

Ms. Barbara S. ONeal
President/Co-Founder
Centric Web®, Inc.
630-734-0741
http://www.centricweb.com
Adobe Community Expert

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Which error?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Tigerlady
Registered: Oct 31 2006
Posts: 20
Actually I meant that it doesn't alert the user that the fields total more than 100%. So it is the alert that isn't working. thanks.

Ms. Barbara S. ONeal
President/Co-Founder
Centric Web®, Inc.
630-734-0741
http://www.centricweb.com
Adobe Community Expert

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Then start debugging it.
Print the value of 'sum' to the console at the end, then print the values of each field and check where the problem is.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Tigerlady
Registered: Oct 31 2006
Posts: 20
try67 wrote:
Then start debugging it.
Print the value of 'sum' to the console at the end,
then print the values of each field and check where the problem is.
I have never did a debug and do not know what you mean by Print the value of the sum. how do i do this?

thanks. sorry for not knowing this. i am still a bit new at trying to do validations in acrobat.

Ms. Barbara S. ONeal
President/Co-Founder
Centric Web®, Inc.
630-734-0741
http://www.centricweb.com
Adobe Community Expert

try67
Expert
Registered: Oct 30 2008
Posts: 2398
To print the value of the sum to the console insert this line at the end of your script:
console.println("Sum=" + sum);
You can use a similar line in the loop to check the value of the fields, such as:
console.println(aFields[i] + "=" + Number(this.getField(aFields[i]).value));

To open the console manually press Ctrl+J.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Tigerlady
Registered: Oct 31 2006
Posts: 20
ok i added the script however nothing shows up in the console unless i put a number in the field that has the validation.

If i type numbers in the other fields nothing happens.

question. should this validation script be in each of the other fields?

this.getField(aFields[i]) has no properties
5:Field:Validate

thanks for sticking with me on this one.

Ms. Barbara S. ONeal
President/Co-Founder
Centric Web®, Inc.
630-734-0741
http://www.centricweb.com
Adobe Community Expert

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Maybe you should specify when you want this validation to happen.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com