Specifying number of answers in mc

272 views
Skip to first unread message

Richard Wundrack

unread,
Jul 3, 2019, 5:38:51 AM7/3/19
to formr
Hi all,

How would I go about specifying a minimum and maximum number of answers for mc items (e.g. I want them to choose at least two but no more than three answers from a list of six answers) and how would I set up the warning if not enough or too many answers have been selected?

Thanks,
Richard

0171 146 27 34





Ruben Arslan

unread,
Jul 3, 2019, 5:50:36 AM7/3/19
to Richard Wundrack, formr
Hey,

use an item of type block with a showif. You'll need to write some javascript to count the commas.
I haven't tested this:
(your_item.match(/,/g) || []).length > 1 && (your_item.match(/,/g) || []).length < 4 //js_only 

Best,

Ruben

--
You received this message because you are subscribed to the Google Groups "formr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to formr+un...@googlegroups.com.
To post to this group, send email to fo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/formr/F21B5D90-E1E6-4E18-B19E-9ADA69712F16%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Richard Wundrack

unread,
Jul 25, 2019, 5:49:16 PM7/25/19
to Ruben Arslan, formr
Hi Ruben,

Your solution works perfectly for maximising and minimising the number of answers to mc_multiple items. In fact, it works too good because If I want a minimum number of answers in an mc question that implies there is a warning as long as there is no answer which may be bothersome for participants.

For anyone who cares: Attached is not a perfect toy solution but the only one I could come up with that gives warnings for all cases but one. However, this one is dealt with by a submit-button that only appears if every answer is within the min and max number of answers to choose:

Survey
nametypelabelshowif
testVAR1
mc_multiple_button testListPlease, choose exactly 2 letters!
testblock1
blockYou chose more than 2 letters!(testVAR1.match(/,/g) || []).length > 1 //js_only 
testVAR2
mc_multiple_button testListPlease, choose exactly 2 letters!
testblock2blockEither you chose more than 2 letters in this question and/or less than 2 letters in the previous question! (testVAR2.match(/,/g) || []).length > 1 || ((testVAR1.match(/,/g) || []).length < 1 && ((testVAR2.match(/,/g) || []).length == 1 ||(testVAR2.match(/,/g) || []).length > 1)) //js_only 
testVAR3
mc_multiple_button testListPlease, choose exactly 2 letters
testblock3
blockEither you chose more than 2 letters in this question and/or less than 2 letters in the previous question! (testVAR3.match(/,/g) || []).length > 1 || ((testVAR2.match(/,/g) || []).length < 1 && ((testVAR3.match(/,/g) || []).length == 1 ||(testVAR3.match(/,/g) || []).length > 1)) //js_only 
testVAR4
mc_multiple_button testListPlease, choose exactly 2 letters
testblock4
blockEither you chose more than 2 letters in this question and/or less than 2 letters in the previous question! (testVAR4.match(/,/g) || []).length > 1 || ((testVAR3.match(/,/g) || []).length < 1 && ((testVAR4.match(/,/g) || []).length == 1 ||(testVAR4.match(/,/g) || []).length > 1)) //js_only 
testnotenoteIf there is no "Contiue"-button below, you have not yet chosen two letters for each question. (Check the first and the last question in particular.)
testsubsubmitContinue!!(((testVAR4.match(/,/g) || []).length < 1 && ((testVAR1.match(/,/g) || []).length == 1 || (testVAR1.match(/,/g) || []).length < 1))) //js_only 

choices
list_namenamelabel
testListaa
testListbb
testListcc
testListdd
testListee

Best,
Richard

0171 146 27 34

Ruben Arslan

unread,
Jul 30, 2019, 8:31:43 AM7/30/19
to Richard Wundrack, formr
Thanks for responding back with your final solution.
You may also find the first special case here helpful to only show the message once there is an answer (but I guess it would still show, once you check the first box, so yours is more elegant): 

Paula Teich

unread,
Oct 22, 2020, 10:57:13 AM10/22/20
to formr
Hi everyone,
I want to do something similar:

Exactly 2 answers have to be chosen, more or fewer answers should not be possible.
Otherwise participants shouldn't be able to continue the survey by clicking on the submit button.

I tried using a block item and a showif with this code: (multiplechoice_comprehension1.match(/,/g) || []).length > 2 && (multiplechoice_comprehension1.match(/,/g) || []).length < 2 //js_only
However, this item doesn't show at all when I test the survey.

Can you tell me what I'm doing wrong, or is there another way of doing it (especially not making it possible to continue before the correct number of items are chosen).

Any help would be greatly appreciated - Thank you very much in advance!

Best, Paula

Paula Teich

unread,
Nov 4, 2020, 9:33:56 AM11/4/20
to formr
I also tried this: If participants do not pick the 2 correct answers of the mc-questions (if they choose more, fewer or the wrong combination of two answers) they should be told that they cannot continue the study.
So this item (saying they cannot continue) should only appear if the combination of the 2 correct answers (in this case answers number 2 + 3) was NOT chosen. I tried using a showif:
multiplechoice_comprehension1!=c(2,3) or multiplechoice_comprehension1!=2 & multiplechoice_comprehension1!=3
Both ways don't work: If only one of the correct answers is chosen, for example, the item (saying the participant cannot continue) doesn't appear, but in this case it should.

Does anyone have an idea how I can correctly specify the showif?  Thanks in advance!

Ruben Arslan

unread,
Nov 9, 2020, 3:21:29 PM11/9/20
to Paula Teich, formr
Hi Paula,

the condition you formulated is impossible (a number cannot be bigger than two and smaller than two).
You need sth like this:

(multiplechoice_comprehension1.match(/,/g) || []).length == 2 && //js_only

Best,
Ruben

Paul Lefebvre

unread,
Feb 25, 2022, 9:10:26 PM2/25/22
to formr
Hi all,

I'm having some difficulty trying to implement the solutions proposed here about requiring a minimum and maximum number of selections in the context of a mc_multiple item. I would like to block participants from submitting unless they have selected between 7 and 12 options from the mc_multiple item. Using the following js in the showif for a block I almost get what I'm looking for:

(MIMIC_POS_values.match(/,/g) || []).length <  6 || (MIMIC_POS_values.match(/,/g) || []).length > 11  //js_only

This works perfectly, blocking progress unless between 7 and 12 options are selected. The problem is that when only one option is selected you can still submit. Progress is blocked if no items, 2:6 items, and 13+ items are selected, but the block doesn't function if a single box is checked. I can't seem to figure out why the block is failing in this odd way. I am definitely a beginner with js, so any suggestions would be much appreciated!

Paul

Cyril Tata

unread,
Feb 28, 2022, 6:54:44 AM2/28/22
to Paul Lefebvre, formr
Hi Paul

Could you send me a link pointing to the page where this problem occurs? Your conditional statement looks okay to me.

best
Cyril


Paul Lefebvre

unread,
Aug 26, 2022, 3:27:51 PM8/26/22
to formr
Hi again,

I think I've figured out the problem I was having with blocking progress unless some specified range of choices in an mc_multiple item were selected. I thought I would share that here in case someone else bumps into the problem.

Desired behaviour: I want a block to engage if participants don't select within a range of choices for an mc_multiple question (say selecting 3 or 4 choices out of 7 options for the purpose of illustrating the issue)

First, I created a block item with the following code in the showif column: (mc_test.match(/,/g) || []).length < 2 || (mc_test.match(/,/g) || []).length > 3 //js_only

This should block progress if the value of the mc_multiple item (mc_test) contains fewer than 3 or greater than 4 selections (by counting the commas in the mc_test string).

Actual behaviour: This block engages when the participant chooses less than three or more than 4 choices, EXCEPT when only one choice is selected. In the case where only one choice is selected the block isn't engaging. This turns out to be because the value of the mc_multiple item is stored as a number when only one option is selected (rather than as a string when no options or > 1 options are selected).

Solution: So, in order to get the block to engage as desired the following code in the showif column of the block seems to work :
typeof mc_test ==="number" || (mc_test.match(/,/g) || []).length < 2 || (mc_test.match(/,/g) || []).length > 3 //js_only

I've attached a test survey just to show the behaviour I've described above. It includes a simple mc_multiple item with 7 choices and some blocks to illustrate.

Paul
testing_block-v2.xlsx
Reply all
Reply to author
Forward
0 new messages