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

Conditional Execution using Check Box

jrenee97045
Registered: Mar 29 2010
Posts: 25
Answered

I really need help with a script. I have three fields: check1 (which is a check box), subtotal (which is a number field that is the total of several other fields), and planrev (also a number field).

What I am looking for is the script that when check1 is checked, it will take the subtotal and multiply it by .25 (or 25%), and result to show in planrev.

I have been laboring over this off and on for days, trying all different kinds of scripts (I'm a newbie to scriptwriting), and I'm just not getting it. Can anyone help me?

My Product Information:
Acrobat Pro 9.3.1, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Put this code in planrev's custom calculation script:
if (this.getField("check1").value=="Yes") {event.value = this.getField("subtotal").value * 0.25;} else event.value = "";

You didn't mention what should happen if the check box is not selected, so I had the script clear the field. You can adjust it if you want.

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

jrenee97045
Registered: Mar 29 2010
Posts: 25
Does the Properties/Options/Export Value need to be set to Yes for the check box? I'm asking because I did a copy and paste and it doesn't seem to work.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Yes. Or you can adjust the script to match your export value.

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

jrenee97045
Registered: Mar 29 2010
Posts: 25
You...are...AWESOME! THANK YOU!
jrenee97045
Registered: Mar 29 2010
Posts: 25
Additional question to this thread:

What if I have a series of check boxes (i.e. check2, check3, etc.), and any one or more of them when checked will set off the conditional execution noted in my original inquiry?

So for further explanation, I have a form, and if my staff checks off check1, check2, and/or check3, it will cause the planrev to calculate the subtotal*.025. How would that be added to the javascript?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You need to change the first line like so:

if (this.getField("check1").value=="Yes" || this.getField("check2").value=="Yes" || this.getField("check3").value=="Yes") {
etc.

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

jrenee97045
Registered: Mar 29 2010
Posts: 25
I had thought about the double bars. My only question in using an "or" (||) is that I want the person to be able to click any one or more of the boxes to set off the conditional execution calculation, and I always thought the "or" meant that only one or another one. I was kind of thinking "and/or." Is there such a thing or will the || still work in this case?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
"Or" in formal logic is not the same as the one used in regular language.
The truth-table of formal "Or" is:
a b a OR b
0 0 0
0 1 1
1 0 1
1 1 1

As you can see, this is actually what we mean when we say "and/or" when we speak, because even if both A and B are true will the result be true.

When people say "Or", they usually mean what's known in formal logic as "Exclusive Or" (or "Xor"), which looks like this:
a b a XOR b
0 0 0
0 1 1
1 0 1
1 1 0

Bottom line, give my code a try and you'll see that it works the way you described it.

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

jrenee97045
Registered: Mar 29 2010
Posts: 25
Okay, so I set my Check Box export value to 0, and this is the code I put in the javascript for planrev, but I get a syntax error on line 2:

if (this.getField("check1").value=="0" || this.getField("check2").value=="0" || this.getField ("check3").value=="0" || this.getField("check4").value=="0" || this.getField("check5").value=="0" || this.getField("check6").value=="0" || this.getField("check7").value=="0" || this.getField("check8").value=="0" || this.getField("check9").value=="0" || this.getField("check10").value=="0" || this.getField("check11").value=="0" || this.getField("check12").value=="0" || this.getField("check13").value=="0" || this.getField("check14").value=="0" || this.getField("check15").value=="0" ||) {
event.value = this.getField("Subtotal").value * 0.25;
} else event.value = "";
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Lose the last ||, just before the closing bracket.

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

jrenee97045
Registered: Mar 29 2010
Posts: 25
I did what you suggested, and it took the code, but it will not run the conditional execution calculation unless the first box is checked, and I need it to run if any one or more are checked. I'll uncheck the first box, then check one or two of the others, and they do not run the conditional execution calculation. Here is the code in the planrev field as I have entered it (copy and paste):

if (this.getField("check1").value=="0" || this.getField("check2").value=="0" || this.getField ("check3").value=="0" || this.getField("check4").value=="0" || this.getField("check5").value=="0" || this.getField("check6").value=="0" || this.getField("check7").value=="0" || this.getField("check8").value=="0" || this.getField("check9").value=="0" || this.getField("check10").value=="0" || this.getField("check11").value=="0" || this.getField("check12").value=="0" || this.getField("check13").value=="0" || this.getField("check14").value=="0" || this.getField("check15").value=="0") {
event.value = this.getField("Subtotal").value * 0.25;
} else event.value = "";


Any suggestions to fix this?
jrenee97045
Registered: Mar 29 2010
Posts: 25
Never mind. I figured it out! Yeah!

Thank you so much for your help with this problem. I can now apply this knowledge in some of my other forms.

You ROCK!

I'll stop bugging you now.