• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Enable CheckBoxes when CheckBox 1 is checked.

Community Beginner ,
May 23, 2020 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.

 

TOPICS
Create PDFs , How to , PDF forms

Views

5.9K

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
community guidelines

correct answers 1 Correct answer

Participant , May 24, 2020 May 24, 2020

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", Ch

...

Votes

Translate

Translate
Participant ,
May 23, 2020 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. 

Votes

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
community guidelines
Community Beginner ,
May 24, 2020 May 24, 2020

Copy link to clipboard

Copied

Hi rjunke,

 

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

Votes

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
community guidelines
Participant ,
May 24, 2020 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.

Votes

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
community guidelines
Community Beginner ,
May 24, 2020 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!

Votes

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
community guidelines
Participant ,
May 24, 2020 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.

Votes

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
community guidelines
Community Beginner ,
May 24, 2020 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.

Votes

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
community guidelines
Participant ,
May 24, 2020 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

 

Votes

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
community guidelines
New Here ,
Jun 11, 2020 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.

 

 

Votes

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
community guidelines
Participant ,
Jun 11, 2020 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.

 

Votes

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
community guidelines
Community Beginner ,
Sep 21, 2020 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.



 

Votes

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
community guidelines
Community Expert ,
May 23, 2020 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

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Beginner ,
May 24, 2020 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.

 

 

Votes

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
community guidelines
Community Expert ,
May 29, 2020 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

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Engaged ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

@steven11980

To begin, I came across this post in the Adobe forum by chance in performing an online search looking for an answer to something else totally unrelated. Anyway, in reading your question along with the answers provided at the time, I was  totally amazed in that none of the answers mentioned the 'isCheckBox' method. Needless to say, this method came immediately to mind in reading your question. To employ this method, create one checkbox named 'checkBox' and four (4) checkboxes each with the same name 'chkBox' and assign a different export value, i.e., A, B, C, and D to each. Next, in the mouse up event for checkbox named 'checkBox' add the following script where event.target refers to the field 'checkBox'. This code will do what you want once the checkBox (same as CheckBox1 in your initial question) has been checked. In other words, once checked the remaining (4) checkboxes will be rendered read-only or unable to be checked. If unchecked, you will only be able to check one of the four checkboxes as needed. IMO, the first answer provided exemplifes making a mountain out of a mole hill.

f=getField("chkBox")
if(event.target.isBoxChecked(0))
f.readonly=true
else
f.readonly=false

Votes

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
community guidelines
Engaged ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

Sorry, in my previous answer I forgot to mention that when you create the four checkboxes with the same name 'chkBox' and different export values, you need to check/assign 'read-only' in the field property's box under 'general'. Also, as for the script in the mouse-up event for your Check Box 1, since you only want to be able to check the other boxes if Check Box 1 is checked, the script should read:

f=getField("chkBox")
if(event.target.isBoxChecked(0))
f.readonly=false
else
f.readonly=true

 

 

Votes

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
community guidelines
Community Expert ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

LATEST

The "isBoxChecked" solution is functionally equivelant in this case, however, I never use this function because the widget number input renders it non-unversal.  There is no way programatically to know the widget number of the field the script is operating on. In this scenario you are assuming there is only one widget because there is one checkbox, but this is not always true. Its best to stick with the simplest generic solution.  the statement, event.target.value!="Off", does not depend on widgets or export values. It is the most universal solution.     

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines