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
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
...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?
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
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;
Copy link to clipboard
Copied
Thanks for this Thom, and sorry for the delay in replying. I’ll give it a go!
Seb
Copy link to clipboard
Copied
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.