Highlighted

Enable CheckBoxes when CheckBox 1 is checked.

New Here ,
May 23, 2020

Copy link to clipboard

Copied

Dear All,

 

I need your great help on Adobe Acrobat .

 

I have CheckBox 1. And another 4 checkboxes which I like to classify them as Other CheckBoxes.

 

I need to do the following:

Other CheckBoxes are only enable when CheckBox 1 is checked. If CheckBox 1 not checked, the Other CheckBoxes cannot be checked.

For Other CheckBoxes, only one of the 4 checkboxes can be checked.

 

Thank you. Appreciate your guidance here.

 

Sorry about that.

To get the behavior you're looking for:

Give the main check box its own name:
My Example: CheckBox


Give the other checkboxes the same name. The resulting names will be:
My example: Choice1#0, Choice1#1, Choice1#2, Choice1#3

These become a part of a group by virtue of having the same name (with#n appended to the name) and allows for only one to be checked just like a radio button.

 

Each of these checkboxes need to have a different export value:
Choice1#0 = "Yes1", Choice1#1 = "Yes2", Choice1#3 = "Yes3", Choice1#4 = "Yes4"

 

Rather than checking the boolean value of the main checkbox, just get its export value, in this case "Yes".

 

Here's the code I used:
var CheckBoxVal = this.getField("CheckBox").value;

if (CheckBoxVal == "Yes") {
this.getField("Choice1").readonly = false;
} else {
this.getField("Choice1").readonly = true;
}

 

Hope this helps.

TOPICS
Create PDFs, How to, PDF forms

Views

717

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Enable CheckBoxes when CheckBox 1 is checked.

New Here ,
May 23, 2020

Copy link to clipboard

Copied

Dear All,

 

I need your great help on Adobe Acrobat .

 

I have CheckBox 1. And another 4 checkboxes which I like to classify them as Other CheckBoxes.

 

I need to do the following:

Other CheckBoxes are only enable when CheckBox 1 is checked. If CheckBox 1 not checked, the Other CheckBoxes cannot be checked.

For Other CheckBoxes, only one of the 4 checkboxes can be checked.

 

Thank you. Appreciate your guidance here.

 

Sorry about that.

To get the behavior you're looking for:

Give the main check box its own name:
My Example: CheckBox


Give the other checkboxes the same name. The resulting names will be:
My example: Choice1#0, Choice1#1, Choice1#2, Choice1#3

These become a part of a group by virtue of having the same name (with#n appended to the name) and allows for only one to be checked just like a radio button.

 

Each of these checkboxes need to have a different export value:
Choice1#0 = "Yes1", Choice1#1 = "Yes2", Choice1#3 = "Yes3", Choice1#4 = "Yes4"

 

Rather than checking the boolean value of the main checkbox, just get its export value, in this case "Yes".

 

Here's the code I used:
var CheckBoxVal = this.getField("CheckBox").value;

if (CheckBoxVal == "Yes") {
this.getField("Choice1").readonly = false;
} else {
this.getField("Choice1").readonly = true;
}

 

Hope this helps.

TOPICS
Create PDFs, How to, PDF forms

Views

718

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 23, 2020 0
Participant ,
May 23, 2020

Copy link to clipboard

Copied

I see this behavior if you do a copy and paste of any kind of form field. If you copy and paste the pasted field names will be the same except the field name will be appended with a # and a unique character. you'll need to make sure the field names are unique without the # extension. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 23, 2020 0
New Here ,
May 24, 2020

Copy link to clipboard

Copied

Hi rjunke,

 

Not very clear what you are saying. Can you elaborate? Thank you.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 24, 2020 0
Participant ,
May 24, 2020

Copy link to clipboard

Copied

Sorry about that.

To get the behavior you're looking for:

Give the main check box its own name:
My Example: CheckBox


Give the other checkboxes the same name. The resulting names will be:
My example: Choice1#0, Choice1#1, Choice1#2, Choice1#3

These become a part of a group by virtue of having the same name (with#n appended to the name) and allows for only one to be checked just like a radio button.

 

Each of these checkboxes need to have a different export value:
Choice1#0 = "Yes1", Choice1#1 = "Yes2", Choice1#3 = "Yes3", Choice1#4 = "Yes4"

 

Rather than checking the boolean value of the main checkbox, just get its export value, in this case "Yes".

 

Here's the code I used:
var CheckBoxVal = this.getField("CheckBox").value;

if (CheckBoxVal == "Yes") {
this.getField("Choice1").readonly = false;
} else {
this.getField("Choice1").readonly = true;
}

 

Hope this helps.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 24, 2020 0
New Here ,
May 24, 2020

Copy link to clipboard

Copied

Hi rjunkie,

 

Thanks a million. Your script works perfectly. I was stuck on this for 2 hours!

But to clarify:

Quote

My example: Choice1#0, Choice1#1, Choice1#2, Choice1#3

Unquote

This didnt work as a group for me. I still group them just based on "Choice 1". I tried the above. but adobe acrobat did not recognise it as a group.

Sincerely appreciate the help rendered!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 24, 2020 0
Participant ,
May 24, 2020

Copy link to clipboard

Copied

You won't see them shown as a group in the list of fields on the right (editing the form), however, they are treated as a group by virtue of them having the same name (Choice1#0, Choice1#1, Choice1#2, Choice1#3) while each checkbox in the "group" has a different export value. 

 

Is this still working for you as desired? If yes, mission accomplished.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 24, 2020 0
New Here ,
May 24, 2020

Copy link to clipboard

Copied

Hi rjunke,

It doesn't for my scenario. Somehow, adobe acrobat does not recognise Choice1#0, Choice1#1, Choice1#2 and Choice1#3 as a goup - i.e. it doesn't enable to only check one of the checkboxes among Choice1#0, Choice1#1, Choice1#2 and Choice1#3. But it works for the scenario if the intention is to allow multiple checks among Choice1#0, Choice1#1, Choice1#2 and Choice1#3 when CheckBox is checked.

But without your script, I would not have gotten to the step to work as what I need.

Many thanks! Sincerely appreciate  your help.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 24, 2020 0
Participant ,
May 24, 2020

Copy link to clipboard

Copied

That's very odd. Acrobat doesn't recognize my sample as a group either, because these are not radio buttons (coded to look like checkboxes), they are standard checkboxes. It is very important they the checkbox names be the same with each one having a unique #n" appended, then the export values for each need to be unique.

 

I tested this code with my version of acrobat (2020 Pro) and it only allows for one checkbox to be checked as I have the code written.

 

Sorry, I don't know why it doesn't work for you.

Go to this link and download my sample and let me know if its not what you want and why.

https://1drv.ms/b/s!AkrEqed-CFsjkYg8qpnmkjy5QjGlUA?e=PkmbVD

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 24, 2020 0
New Here ,
Jun 11, 2020

Copy link to clipboard

Copied

I am so sorry, but I need help on this and CANNOT figure it out. I even tried to use your example verbatim and it's not working. I have Checkbox-A. When CheckboxA is selected I need the two options under it, Checkbox1 & Checkbox2, to become enabled. However, Checkbox1 & Checkbox2 cannot both be selected (see attached image below).

 daniellel74208252_0-1591898213327.png

1. How do I accomplish that?

2. Where do I put the Javascript? Do I slected the boxes individually and put it under the Actions tab, or do I select all three together and put it under teh properties there?

3. Is there a way to accomplish the same idea but with text boxes? If CheckboxB is enabled, can the text box in the same section be enabled.

 

I've tried multiple searched, multiple java codes, and video searches to try to find an answer. I'm sorry if you end up repeating yourself and appreciate any help.

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 11, 2020 0
Participant ,
Jun 11, 2020

Copy link to clipboard

Copied

OK. I understand you're trying to enable/disable a checkbox group using a checkbox. Based on your requirements as I understand them from your post, its easier to use radio buttons than checkboxes for the two choices. The radio buttons will be part of a group and when getting the value of the choice made, you use the group name as the getField. In this example the group name is "Group1". You can change the appearance of the radio button to work like checkboxes.

 

The main checkbox will have the javascript using a mouse up event. Use this code replacing the form field names with yours.

 

var checkbox = event.target.value;

if (checkbox == "Yes") {
	this.getField("Group1").readonly = false;
	this.getField("Group1").borderColor = color.black;
	// The below is option al and added just added cosmetic formatting
	// for the benefit of the form user.
	this.getField("Group1").textColor = color.black;
	// These are the field names of each radio button. You don't need to reference
	// this since the value will be the chice made assigned to the group.
	this.getField("ChoiceALabel").textColor = color.black;
	this.getField("ChoiceBLabel").textColor = color.black;
} else {
	this.getField("Group1").value = "";
	this.getField("Group1").readonly = true;
	// The below is option al and added just added cosmetic formatting
	// for the benefit of the form user.
	this.getField("Group1").borderColor = color.gray;
	this.getField("Group1").textColor = color.gray;
	// These are the field names of each radio button. You don't need to reference
	// this since the value will be the chice made assigned to the group.
	this.getField("ChoiceALabel").textColor = color.gray;
	this.getField("ChoiceBLabel").textColor = color.gray;
}

 

You will need to use "this.getField("Group1").value" for the choice made from the radio buttons in the rest of your form.

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 11, 2020 0
New Here ,
Sep 21, 2020

Copy link to clipboard

Copied

Hi. Unfortunately, I have a similar problem, maybe a little different. I tried to do it like this.
I have the main boxes (Check Box 1, 2, 3, 4, 5, 6). However, they must be mutually exclusive and both 
cannot be selected. I made hiding from the Check box Properities / Actions / Mouse up / Run javascript
function.
if (this.getField("Check Box1").value=="Off" && this.getField("Check Box2").value=="Off" && this.getField("Check Box3").value=="Off" && this.getField("Check Box4").value=="Off"){
this.getField("Box32").display = display.hidden;
this.getField("Box32").value="Off";
this.getField("Box69").display = display.hidden;
this.getField("Box69").value="Off";
}
else {
this.getField("Box32").display = display.visible;
this.getField("Box69").display = display.visible;
} They are supposed to hide and show boxes (Box ...). As long as they just hide and show it's okay.
When I try to do a Check Boxes group exclusion this feature is not working. Written in the
Javascript panel.

var firstGroup = [this.getField("Check Box1"),this.getField("Check Box2"),this.getField("Check Box3")];


function checkFirstGroup(box)
{
for(var i=0;i<firstGroup.length;i++)
{
if(firstGroup[i] != box)
{
firstGroup[i].value = "Off";
}
}
}

 

 
And this feature doesn't work anymore. I only added that I wanted to do groups and exclusion 
in Boxes. And I have 80 boxes. Maybe on these two boxes (32, 69) I will be able
to understand it, if you can help me.



 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 21, 2020 0
Adobe Community Professional ,
May 23, 2020

Copy link to clipboard

Copied

Give all the "Other"checkboxes the same name, but different export values. This makes them a mutually exclusive group.

Next add this code to a MouseUp "Run a JavaScript" action on the first checkbox

 

this.getField("OtherCheckbox").readOnly = (event.target.value == "Off");

 

See this article for info on scripting checkboxes/radio buttons.

https://www.pdfscripting.com/public/Checkboxes-and-Radio-Buttons.cfm

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 23, 2020 0
New Here ,
May 24, 2020

Copy link to clipboard

Copied

Hi Thom,

 

Thanks for the prompt reply. My apologies, your suggestion does not work as expected. The end result as follows: If  "CheckBox 1" is check, the "Other CheckBoxes" is checkable; If  "CheckBox 1" is uncheck, the "Other CheckBoxes" is still checkable. Prior to posting here, I tried what you have proposed.

 

The closest I could get to was:

For the "Other CheckBoxes", I have named them as "OtherCheckBox" and assigned a different export value 1, 2, 3 and 4 respectively.

For CheckBox 1, I have added a script as below:

// set readonly property based on the value of this field compared to "Off";

this.getField("OtherCheckBox").readonly = (event.target.value != "Off");

The end result as follows: If  "CheckBox 1" is check, the "Other CheckBoxes" is uncheckable; If  "CheckBox 1" is uncheck, the "Other CheckBoxes" is uncheckable.

 

Would you be able to advise again? Thank you.

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 24, 2020 0
Adobe Community Professional ,
May 29, 2020

Copy link to clipboard

Copied

The script works as specified, so something else is the problem. You'll need to do some debug.

Is anything reported in the console window?

 

Add a console.println() statement to the sdript to display the value of "event.target.value"

 

you'll find a tutorial on the console window here:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 29, 2020 0