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

Acrobat XI Pro Form: at least one of six checkboxes is required to be checked

New Here ,
Aug 13, 2016 Aug 13, 2016

Copy link to clipboard

Copied

Hi,

I am creating a form using Adobe Acrobat XI Pro.

On one part of the form, there are 6 different checkboxes in a row, of which, at least one is required to be checked.

Is there some javascript that I can use, so that when a user goes to the textfield after the checkboxes, that it will not let them go further, until they go back and check one of the boxes?

Or, if I can't have that ...  some javascript code that will not let them "submit" the form if one of the checkboxes is not checked?

I would appreciate any help.

Thank you.

TOPICS
Acrobat SDK and JavaScript

Views

668

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

correct answers 1 Correct answer

Community Expert , Aug 14, 2016 Aug 14, 2016

The former is problematic and I would not pursue it.

The latter is possible, but requires using a custom-made script. One easy way of doing it is creating a required (hidden) text field with the default value "Off" and use a script to copy the values of the check-boxes into it. That way, if no value is entered, the validation of that field will fail.

Likes

Translate

Translate
Community Expert ,
Aug 14, 2016 Aug 14, 2016

Copy link to clipboard

Copied

The former is problematic and I would not pursue it.

The latter is possible, but requires using a custom-made script. One easy way of doing it is creating a required (hidden) text field with the default value "Off" and use a script to copy the values of the check-boxes into it. That way, if no value is entered, the validation of that field will fail.

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
community guidelines
New Here ,
Aug 14, 2016 Aug 14, 2016

Copy link to clipboard

Copied

Hi Try67,

Thank you very much for your advice.

By any chance, would you be able to give me the javascript code that would do what you suggest?

Also, I am not sure how to make the default value = "Off" on a text field.  I looked, but I do not see that option.

I would really appreciate it, if you could give me the javascript code, and tell me if I would apply the javascript code via the "Actions" tab, using the "Run a javascript" action, or if I would apply it via the "Calculate" tab using the "Custom Calculation Script" area.

Your help is very much appreciated.

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
community guidelines
New Here ,
Aug 14, 2016 Aug 14, 2016

Copy link to clipboard

Copied

omg ...   hi Try67,

I found some old code of your's online and I tried it....

I made a required, hidden text field.  I placed it at the end of the row of checkboxes.  Then, I put your code into the Custom Calculation Script area under the Calculate tab.

This is the code I used:

var checkboxes = ["CkRTPY","CkRTBen", "CkRTWFA", "CkRTGL", "CkRTRpt",  "CkRTUnk"];

var v = "";

for (var i in checkboxes) {

     if (v=="" && this.getField(checkboxes).value!="Off")

          v = "OK";

}

  1. event.value = v;

... and it worked!!!    Upon Submit it will not let me submit because it says that something required is not filled in.  I had all of my other required fields filled in already...  That's how I know it is the checkboxes...

Only one slight problem now ...  The checkboxes do not get highlighted in red, like all of the required text fields do, when you try to submit them, when they are not filled in.

Is there any way we can make it so it highlights the checkbox area, when at least one of them is not checked?

Thank you ahead of time for your help.  I'm getting very excited...  I really hope there is some way to show that it is the checkboxes that are the missing required item.

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
community guidelines
New Here ,
Aug 14, 2016 Aug 14, 2016

Copy link to clipboard

Copied

oops ...  the last line of your code should not have an 'a' in it...   I must have hit that by mistake.

last line of code is really:

event.value = v;

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
community guidelines
New Here ,
Aug 14, 2016 Aug 14, 2016

Copy link to clipboard

Copied

Hi Try67,

I just figured out the last part of my question regarding making the checkboxes be highlighted in red, when at least one of them is not checked.

I made the Hidden Text Field be "not hidden."  I stretched it to fit the length of the row of checkboxes, so that they were all encompassed by it.  Then I sent that text field "behind" the row of checkboxes.  Now, when none of the boxes are checked, the red line of the text field goes around the whole row of checkboxes, showing that they are the unsatisfied required group.

Also, there was some text in the textfield, based on the calculation javascript that we had attached to the text field.  When all is well, it says "OK" inside the text field.  I went to the properties of the text field and changed the text color from black to white, so it won't show up.

Anyways, thank  you very much for your help.  Your original code that I found online is what helped me get going.

I appreciate it very much.

Regards.   : )

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
community guidelines
Community Expert ,
Aug 15, 2016 Aug 15, 2016

Copy link to clipboard

Copied

That's a neat solution. Glad you found it and shared it with us...

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
community guidelines
Community Expert ,
Aug 15, 2016 Aug 15, 2016

Copy link to clipboard

Copied

PS. I assume you found it already, but if you didn't you can set the default value of a text field via its Properties - Options tab.

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
community guidelines
New Here ,
Sep 27, 2016 Sep 27, 2016

Copy link to clipboard

Copied

Hi try67,

Actually, at the time you wrote this about the Properties / Options tab, I had not found it still.  So, thank you for giving me that information.  Can't believe I didn't see it, until you told me where it was.  Kind of obvious.   : P

Thanks.   : )

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
community guidelines
New Here ,
Aug 09, 2021 Aug 09, 2021

Copy link to clipboard

Copied

I'm trying to do something similar. How do I send the text field "behind" the row of check boxes?

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
community guidelines
LEGEND ,
Aug 09, 2021 Aug 09, 2021

Copy link to clipboard

Copied

LATEST

You should never try to overlap visible form fields. It is not defined which one is on top and there is no way to set or change which one is on top. If it must occupy the same space, you need to hide the other boxes.

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