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

Using a check box as the basis of calculation

Callum
Registered: Mar 25 2011
Posts: 1

Hi All
Am new to Java and have a form which asks if for a box to be checked if 'yes'. If this condition is met I want the value of 'Field1' to be a value taken from 'Field2' and multiplied by 10.
 
Sounds simple - but I cannot get it! Can anyone help please? Thanks!

My Product Information:
Acrobat Pro Extended 9.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
As the MouseUp action of the check-box (let's say it's called CheckBox1) select "Execute JavaScript", and enter the following code:

if (this.getValue("CheckBox1").value=="Yes")
this.getField("Field1").value = this.getField("Field2").value * 10;

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

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
Have you looked at How to do (not so simple) form calculations and Conditional Executionby Thom Parker?They will show you how to enter a script into the calculation tab and show how an simple 'if' statement works.

It is even possible to use the simplified field notion, just set the export value of the check box to 1. Be careful about how you name your fields. Assuming your check box is 'CheckBox1' then you code for 'Field1' would be:

Field2 * 10 * CheckBox1

SincFielde the simplified field notation will tread the unchecked value as Zero eve though it is the string 'Off'.

You could even use the option for the 'Field is the product of fields:', if you have a field with a default value of 10.




George Kaiser

try67
Expert
Registered: Oct 30 2008
Posts: 2398
I would like to revise my advice from earlier... The problem with that approach is that the field (Field1 in this case) doesn't update when Field2 is updated, only when the the box is clicked. Sometimes you want that to happen, but if you don't the way to do it is to use the custom calculation script for Field1 with a code like this:

if (this.getValue("CheckBox1").value=="Yes") {
event.value = this.getField("Field2").value * 10;
} else {
event.value = ""; // or something else, depending on your requirements
}

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