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

Using checkbox to subtract value

sekkrona
Registered: Jun 7 2010
Posts: 8

I´m having trouble understanding how to subtract a sum from a combobox by using checkbox with a given value.
There are two posts in the combox ("105" and "210"). There are three checkboxes representing a value of "42", "74" and "147". When checked (either one, two or three) that value should be deducted from the value in the combobox.

Any help in this would be much appreciated.

This script is probably horribly wrong, but it is what I have laborating with:

var A = Number(this.getField("komb7").value);
var B = (this.getField("kry1").value);
var C = (this.getField("kry2").value);
var D = (this.getField("kry3").value);
if(this.getField("kry1").isBoxChecked(0))
event.value - = 42;
if(this.getField("kry2").isBoxChecked(0))
event.value - = 74;
if(this.getField("kry3").isBoxChecked(0))
event.value - = 74;
event.value = A-B-C-D;

My Product Information:
Acrobat Pro 8.1.7, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I don't really follow what you're trying to do, but just by looking at the script I see that there are some problems.

This entire part
if(this.getField("kry1").isBoxChecked(0))event.value - = 42;if(this.getField("kry2").isBoxChecked(0))event.value - = 74;if(this.getField("kry3").isBoxChecked(0))event.value - = 74;

is useless if afterwards you set event.value to
event.value = A-B-C-D;
See what I mean?

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

sekkrona
Registered: Jun 7 2010
Posts: 8
Hmm, got it. Did too much apparently when it all came down to:

var A = Number(this.getField("komb7").value);
if(this.getField("kry1").isBoxChecked(0))
A -= 42;
if(this.getField("kry2").isBoxChecked(0))
A -= 74;
if(this.getField("kry3").isBoxChecked(0))
A -= 74;
event.value = A;

worked like a charm :-)
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Now that looks much better...

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

sekkrona
Registered: Jun 7 2010
Posts: 8
Thank you. It´s just like this, being a newbi to Javascript in Acrobat. Trial and error (apparently mostly errors). Being looking at your site. Wonderful stuff!