Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

How to make two checkboxes mutually exclusive?

More
18 hours 9 minutes ago #273090 by Printemps
Your LimeSurvey version: Cloud Version 6.15.22
Own server or LimeSurvey hosting: LimeSurvey hosting in Germany
Survey theme/template: (inherit) vanilla
==================
Hello everyone,

There is an issue that I cannot resolve.

I have a question with three answers, let's call them Y, N and NU.
There are several sub-questions, each making a row. Thus, each row has the column Y, N and NU.
I have used the question type Array/numbers so that all inputs are checkboxes.

I would like to make Y and N mutually exclusive while NU remains unaffected, such that (Y;NU) and (N;NU) are valid answers for each sub-questions but not (Y;N). This may take the form of an error message if both Y and N are selected for the same sub-question or of an automatic unchecking of Y or N when either is being checked next in the same sub-question.

I understand that I cannot use javascript to resolve this since I am on the free plan.
I have tried to use the question validation feature with something like this:
sum(
    if(!is_empty(Q1_SQ001_SQ004.NAOK) and !is_empty(Q1_SQ001_SQ005.NAOK), 1, 0),
    if(!is_empty(Q1_SQ002_SQ004.NAOK) and !is_empty(Q1_SQ002_SQ005.NAOK), 1, 0),
    if(!is_empty(Q1_SQ003_SQ004.NAOK) and !is_empty(Q1_SQ003_SQ005.NAOK), 1, 0)
) == 0

In the above example, my sub-questions have the codes SQ001-3 and the answers have the codes SQ004-6; I have checked the survey with the inspect element and these were the correct names being used. I have tried different versions of the above example to account for a potential misuse of functions but in all cases the survey indicates that the question hasn't been properly answered and refuses to terminate even though I would only select theoretically valid answers during trial.

I don't know if there is something that I am missing or if the precise feature isn't available to me. I have checked the manual and the forum (using my own keywords) and haven't found a similar issue.

I'll be happy to receive precisions, a working answer, a simpler alternative or be pointed to a similar resolved case.

Thank you.

Please Log in to join the conversation.

More
3 hours ago #273092 by Joffm
Hi, a solution could be:
Code the x-axis like
E1: Y
E2: N
U3: NU
Now you can use the variable "self" to only select the exclusive columns (therefore "E")
And with "Y01", "Y02", ... as codes of the y-axis the question validation expression is
(linefeed only for clarity)
Code:
count(self.sq_Y01_E.NAOK)<2 and
count(self.sq_Y02_E.NAOK)<2 and
count(self.sq_Y03_E.NAOK)<2 and
count(self.sq_Y04_E.NAOK)<2



I did not check your approach for errors.
In such cases you'd better send the lss export of the relevant questions.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose