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

How can you make check boxes select one only?

Community Beginner ,
Jul 09, 2013 Jul 09, 2013

Copy link to clipboard

Copied

I am working on locking down a registration form. There are a couple sections that have multiple checkboxes but ONLY one can be marked. We won't even accept the form if there is more than one option marked. Most sections there are two boxes, check one but not the other. There is one section though that has 16 boxes, and yes only one can be marked.  Can I do that?

Similarly I also need to do the same thing with two text fields, only one should be filled out.

THANKS!

TOPICS
PDF forms

Views

172.3K

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
2 ACCEPTED SOLUTIONS
Community Expert ,
Feb 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

You can use something like this as the field's custom validation script:

this.getField("Other field name").readonly = (event.value!="");

View solution in original post

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 ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

1)  Give all the check boxes the same name. 

2)  Make the export value (on the Options tab of the properties dialog) different for each.

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

View solution in original post

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 ,
Jul 09, 2013 Jul 09, 2013

Copy link to clipboard

Copied

It's easy with check-boxes: Give them the same name but different export

values.

Not so simple with text fields... You'll need to figure out how you want it

to work. Should the other fields be locked when one field is filled-in, and

then unlocked when it's made empty again? Should they all remain editable,

but if you fill one of them the others reset?

All of this will have to be achieved with scripts.

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 ,
Jul 09, 2013 Jul 09, 2013

Copy link to clipboard

Copied

Thanks! That worked perfectly!

As far as the test fields, I would prefer that they field would be locked when one is filled and unlocked when the other is cleared. Any thoughts?

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 ,
Feb 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

You can use something like this as the field's custom validation script:

this.getField("Other field name").readonly = (event.value!="");

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 ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

I'm slightly lost on this. I have a form that asks 20 questions with 6 checkable boxes to choose ONE answer from.(N/A, inferior, below avg, avg, above avg, superior) I am trying to only allow one checked box per 6 choices to be accepted, i.e. check one then another the original checked box is erased per question. Every box has a different name, 20 questions x 6 choices = lots of boxes but, I only want one answer per question. Please help. KISS method please.

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 ,
Jan 22, 2019 Jan 22, 2019

Copy link to clipboard

Copied

1)  Give all the check boxes the same name. 

2)  Make the export value (on the Options tab of the properties dialog) different for each.

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
New Here ,
Jan 23, 2019 Jan 23, 2019

Copy link to clipboard

Copied

worked like a charm, thanks

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 10, 2020 Jun 10, 2020

Copy link to clipboard

Copied

Thank you Thom! I kept think change it to what, but the link was very thorough, much appreciated!!

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 15, 2021 Jun 15, 2021

Copy link to clipboard

Copied

Hi @Thom Parker or @try67 ,

 

I was able to get the multiselect checkboxes to work fine for normal documents, but when I upload the document to adobe sign it seems to convert these checkboxes to radio buttons.  Is there anyway around this?  See example attached.  The left is the form in adobe sign.  The right is the same form in adobe acrobat.

Thanks,

Ben

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 ,
Jun 17, 2021 Jun 17, 2021

Copy link to clipboard

Copied

Adobe sign is not PDF. It's a very different format. If the form is for Adobe Sign, then convert it in the Acrobat "Prepare Form" panel. As soon as it's converted you'll notice that all the controls change. Whats there is what you get in Adobe Sign.

 

 

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
New Here ,
Jun 17, 2021 Jun 17, 2021

Copy link to clipboard

Copied

@Thom Parker I have the document open in Prepare form that is where we are testing the form currently.  Are you saying I need to convert it to a different data type?  How do I go about this from the "Prepare Form" panel.  When I click preview in prepare for the grouped checkboxes work.  When I upload to sign though it changes the grouped checkboxs to radio buttons.  Thanks for the help, Ben.

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 ,
Jun 24, 2021 Jun 24, 2021

Copy link to clipboard

Copied

Look on the "More" menu. The first item converts to either Adobe Sign or a regular AcroForm. 

As shown here:

ThomParker_0-1624565261231.png

ThomParker_0-1624565524106.png

 

 

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 ,
Jan 23, 2024 Jan 23, 2024

Copy link to clipboard

Copied

I have 2 'yes' or 'no' questions where one must be checked for each question.  This suggestion worked for requiring one or the other (each question, I made the export value 'yes' or 'no', but kept the name the same).  Now, if either of those questions have the 'yes' option selected, there is a sub question below it where you should explain why the answer is 'yes' with further details.  How do I make that 'if yes, then...' blank a requirement when either above question has a 'yes' response?

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 ,
Jan 24, 2024 Jan 24, 2024

Copy link to clipboard

Copied

Make the explanation field hidden and then show it when the yes is checked. 

See this article:

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.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
New Here ,
Jul 14, 2021 Jul 14, 2021

Copy link to clipboard

Copied

Hi,

I would like to limit the selection of tick boxes to only 3. I tried the below and it's now limited to only 1 selection. how do i make this 3 instead of 1?

1)  Give all the check boxes the same name. 

2)  Make the export value (on the Options tab of the properties dialog) different for each.

 

This is the list fo check boxes I have with tick boxes infront of each:

Main Contractor
Consultant
Sub-contractor
Developer
MEP Contractor
Project Management
Engineering

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
Community Expert ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Setting up multiple check boxes to select a set number is a completely different issue that requires a script. The script needs to count the number of active checks and then uncheck the last one if it goes over. There are several ways to create a solution but the easiest is to use a MouseUp script

 

First,  Give all checkboxes unique name, but put them in the same field group.

For example. Name them like this "Check.Box1" "Check.Box2", etc.  

In this case the group name is "Check".  The exports can be whatever you want. I'd suggest keeping the unique export names.

 

Second, Add this script to the MouseUp on each checkbox

 

var nMax = 3;
if(event.target.value != "Off")
{
	var nCnt = 0;
	this.getField("Check").getArray().forEach(function(a){if(a.value != "Off") nCnt++;});
	if(nCnt > nMax)
		event.target.value = "Off";
}

 

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
New Here ,
Jul 20, 2021 Jul 20, 2021

Copy link to clipboard

Copied

Hi Thom,

I'm trying to do this exact thing and tried to do what you said. But it is still not working.

The problem might be when I try to add the script to each check box, I select MouseUp then Add Javascript, I copy pasted your code but there is no confirmation button or anything, do I just close the tab...? This is what I did but it doesn't work.

 

Let me know the steps to really add the script to each check box please.

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 ,
Jul 20, 2021 Jul 20, 2021

Copy link to clipboard

Copied

The way to know if the script was really added to the MouseUp is to edit it  second time. If the code is there you'll see it.

 

If you are using the Acrobat native code editor, then there is an "Ok" button at the bottom of the dialog. Just closing the dialog will not add the script.

 

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
New Here ,
Jul 20, 2021 Jul 20, 2021

Copy link to clipboard

Copied

Hi Thom,

There is no OK button anywhere... Here is what pops up when I try to add a java script by mouseup to a check box. I work with Adobe Acrobat DC (it'S in French though sorry about that).

''Annuler/Cancel'' just deletes what I've done then ''Atteindre'' asks me a number of ligns, I write one down but still I'm always sent back to the same initial window with no OK button to be seen.

 

Let me know what I should do? Or if there's another to allow only 3 answers from 12 selections. Thanks a lot!

 

adobe question.png

 

 

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 ,
Jul 20, 2021 Jul 20, 2021

Copy link to clipboard

Copied

There is something wrong with the dialog. Try resizing it with the gripper on the bottom right corner. You should also reduce the font size. The font size is a setting in the JavaScript preferences.  You'll find the preferences at the bottom of the Edit menu.

 

 

 

 

 

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
New Here ,
Jul 20, 2021 Jul 20, 2021

Copy link to clipboard

Copied

By resizing it with the gripper it added the OK button thank you 🙂

Now I can add the script but it is still not working. 

All the checkboxes are under the same Question6 and are name Check.Box1 Check.Box2 etc.

I can still only select one instead of 3 even with the script added.

I also tried it just in case with checkboxes not linked under the same question and it's not working either.

 

What would you recommend? 

Thanks a lot for 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
Community Expert ,
Jul 21, 2021 Jul 21, 2021

Copy link to clipboard

Copied

Now it's time to do some debug. Are there any errors reported in the  Console Window?

Were the scripts added to every checkbox in the group?

Watch the Console Window Video here to get started:

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
Community Beginner ,
Dec 13, 2022 Dec 13, 2022

Copy link to clipboard

Copied

Hey Thom, 

 

Could nMax be set to 1 to limit the selectable checkboxes to one?

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 ,
Dec 13, 2022 Dec 13, 2022

Copy link to clipboard

Copied

Yes, but what would be the point?  Only one selection is the default behavior for radio and checkbox groups. 

 

Keep in mind that Acrobat JavaScript is only implemented on a small number of PDF viewers. And most of those only implement a small subset of the model.  Including a script where is is totally unnecessary will limit the usability of the form for no reason.  

 

 

 

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
New Here ,
May 21, 2018 May 21, 2018

Copy link to clipboard

Copied

It's easy with check-boxes: Give them the same name but different export

values.

different export values

How?

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