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

Conditional formating of three or more checkboxes

patman
Registered: Oct 2 2011
Posts: 7

I have a form designed in Adobe Acobat Professional 8.1.0. In it are a few check boxes. If there are say 3 check boxes CheckBox1, Checkbox2 and CheckBox3, I would like the following conditions to work:
all check boxes are unselected,
checkbox1 is selected,
checkbox2 is selected,
if both checkox 1 and checkbox2 are selected then only checkbox3 to be selected,
if checkbox3 selected then checkbox 1 and checkbox2 to be unselected.
 
I tried to place this javascript code in Checkbox3 Mouseup event
 
var cb1 = this.getField("CheckBox1");
var cb2 = this.getField("CheckBox2");
if (this.rawValue == 1) {
cb1.rawValue = 0;
cb2.rawValue = 0;
}
 
I am unable to get it to work.
 
What am I doing wrong?

patman

My Product Information:
Acrobat Pro 8.1, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
It looks like you're mixing code intended for a form created in Acrobat with code intended for a form created in LiveCycle Designer. Which are you using? If Acrobat, what is the export value you set up for CheckBox1 and CheckBox2?
patman
Registered: Oct 2 2011
Posts: 7
I am using Acrobat Pro 8.1, the export value set up for CheckBox1 and CheckBox2 is Yes for both.

I modified the code to

var cb1 = this.getField("CheckBox1")
var cb2 = this.getField("CheckBox2")
var cb3 = this.getField("CheckBox3")

if (cb3.rawValue = 1) {
cb1.value = "False"
cb2.value = "False"
cb3.value =="True";
}
Now if both CheckBox1 and CheckBox2 are selected and I select CheckBox3 Then Checkboxes 1 and 2 get deselected and CheckBox3 stays selected. I need to work out the logic for the CheckBox1 and CheckBox2 to ensure that if either one is the second Checkbox to be selected then Checkbox3 gets selected and Checkboxes 1 and 2 get deselected.


Thank You for you prompt reply.

patman

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
If you're using Acrobat, the correct code for the Mouse Up event of Checkbox3 would be something like:

var cb1 = this.getField("CheckBox1");
var cb2 = this.getField("CheckBox2");

// If this check box is selected, deselect the other check boxes
if (event.target.value !== "Off") {
cb1.value = "Off";
cb2.value = "Off";
}

The rawValue property is not a property of acroform fields. It only works with XFA forms created in LiveCycle Designer.

Also, the following line:

if (cb3.rawValue = 1) {

uses the assignment operator (=), not an equality operator (== or ===), which is what you need to use here.

You description of how you want the rest of it to work is not clear to me, so get this working first and post again if you get stuck.
patman
Registered: Oct 2 2011
Posts: 7
Thanks, I got CheckBox3 to work. Now I need the other 2 to work.

Let me clarify what I am trying to do. Say there is a line in the form
Do you Like:
Red Apples (Checkbox1)
Green Apples (CheckBox2)
Both(CheckBox3).

What I am trying to do is to get Checkbox3 to get checked upon trying to check the second checkbox if the first one is already checked.

PS: The code that I posted also seem to work. I wonder why?

patman

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Why not use radio-buttons? They make much more sense in this context.

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

patman
Registered: Oct 2 2011
Posts: 7
The only problem is that I am unable to get all three radio buttons in the "off" position, if I so desire.

patman

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Then use check-boxes with the same name but different export values.

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

patman
Registered: Oct 2 2011
Posts: 7
I thought there could be only "Yes" and "Off" as export values. Hence could only be used for 2 Check Boxes.

patman

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You can set the "on" value to whatever you want. It's in the properties window.

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

patman
Registered: Oct 2 2011
Posts: 7
I am not sure how to achieve what I want with your suggestion.

Let me try and explain what I am trying to do

Say there is a line in the form

Do you Like: Red Apples (Checkbox1) Green Apples (CheckBox2) Both(CheckBox3)

In the above scenario I would like the following outcomes:

1. If Checkbox3 is checked then Checkboxes 1 and 2 get unchecked
2. If either Checkbox 1 or Checkbox2 is checked and the user decides to check the other Checkbox, either 2 or 1 as the case may be, then for Checkbox3 to be checked and Checkboxes 1 and 2 to be unchecked.
3. All the Checkboxes to remain unchecked

I was able to achieve item # 1 with the above javascript. Item # 3 is possible with Checkboxes. I am having trouble with Item # 2

Thanks for your continued interest

patman

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Then use a drop-down box with the following items:
"-", "Red Apples", "Green Apples", "Both"

It just seems unnecessary to me to script it when there are other options which are much more user-friendly and intuitive.

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

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
I agree with try67. The behavior you're wanting seems awkward and non-standard and I think this particular question should rethought. It seems more straightforward to include just the first two check boxes and allow them to select none, one, or both.
patman
Registered: Oct 2 2011
Posts: 7
I agree with you. I will have to make that suggestion to the powers that be. Personally I am switching to pears.

patman