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

If I have 5 check boxes, how can I make it so only 2 of the 5 can be selected at the same time

Community Beginner ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

I want to create a quiz that contains a question with 5 possible answers. To do this I use check boxes. Out of those 5 answers, only 2 are correct.

I know how to restrict a set of check boxes so only 1 can be ticked at a time. However, is there any way to make it so that only 2 can be ticked st a time?

Thom Parker​ - I’ve seen your name all over other threads so I’m hoping you know the answer

TOPICS
PDF forms

Views

858

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

If the checkbox names are all grouped with a prefix, i.e. "Group1.check1", then here is a script for counting checks

Put this code into a calculation script, in a hidden text field.

var aFlds = this.getField("Group1").getArray();

var nCnt = 0;

aFlds.forEach(function(a){if(a.value!="Off") nCnt++;});

// next, test the current value

if((event.source.value != "Off")&& (nCnt > 2))

  this.Set = "Off";

else

  this.Set = null;

Then add this code to the mouseUp Action of every checkbox

if(this.Set)

   event.target.v

...

Votes

Translate

Translate
Community Expert ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

There's no built-in methodology for this. It has to be done with a script. And it's complicated because you have to both count the number of checks and then disable the latest mouse click. These scripts go to different locations.

Do you have any experience scripting?

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

Copy link to clipboard

Copied

Hi Thom,

Thanks for replying so quickly.

I don’t really have any experience with scripting. I tend to search online and find the piece of code I need. However, I don’t understand why Code is written the way it is.

I guess if this particular scripting is complex then I’ll opt not to do it, because I will need to rely on other designers being able to amend the documents on future...and they will have even less experience than 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 ,
Jan 24, 2019 Jan 24, 2019

Copy link to clipboard

Copied

If the checkbox names are all grouped with a prefix, i.e. "Group1.check1", then here is a script for counting checks

Put this code into a calculation script, in a hidden text field.

var aFlds = this.getField("Group1").getArray();

var nCnt = 0;

aFlds.forEach(function(a){if(a.value!="Off") nCnt++;});

// next, test the current value

if((event.source.value != "Off")&& (nCnt > 2))

  this.Set = "Off";

else

  this.Set = null;

Then add this code to the mouseUp Action of every checkbox

if(this.Set)

   event.target.value = this.Set;

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 ,
Feb 03, 2019 Feb 03, 2019

Copy link to clipboard

Copied

Thanks for this Thom, and sorry for the delay in replying. I’ll give it a go!

Seb

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 ,
Mar 01, 2021 Mar 01, 2021

Copy link to clipboard

Copied

LATEST

Greeting Thom and everyone, I have something similar that would like to have your advice. Actually i have 100 plus question with 3 choices: Yes, No, NA. The default No is check (cross). What i want is if I check Yes or NA, the cross check in check box of No is removed. Thanks for your kindly support as I have no idea how to write a script. 

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