The anyChecked
function can be included in conditional statements, using a specified question and a set of response options as input. It returns "true" if any specified options are selected and "false" if none are selected.
1. Which of the following sodas have you purchased in the last 2 months?
type: checkbox
randomize: y
1. Pepsi
2. Coke
3. Mountain Dew
4. Sprite
5. Cheerwine
6. Mug Root Beer
99. None of these {exclusive: y}
2. Are there other soda brands you drink instead?
type: radio
showif: anyChecked($Q1,99)
1. Yes
2. No
Tip! The inverse of anyChecked
is noneChecked
, which may be preferable depending on the logic required.
Details
-
anyChecked
checks for a single option or a set of options. When specifying multiple options, separate them with commas, e.g.,anyChecked($Q1,1,2)
. - To specify consecutive options, use two dots to define a range (also known as series syntax), e.g.,
anyChecked($Q1,1..4,7)
. - If no options are specified,
anyChecked
returns "true" if the question referenced has any options selected, e.g.,anyChecked($Q1)
. - When used on a listcall in a
condition
decorator, the[id]
placeholder allows any selected option to make the statement true. -
anyChecked
also accepts option data (custom data) when used in acondition
decorator on a list.
Additional examples
Applying conditions to a listcall
anyChecked
can be used in a condition
decorator on a listcall to apply a condition to every element in that list. The [id]
placeholder is replaced with each option ID from the list. For example, the condition for option 1 becomes anyChecked($Q3,1)
. If the option was selected in Q3, then it will be shown in the follow up question Q3A.
setlist: RESTAURANTS
1. Ed Boudreaux's Bayou BBQ
2. Rosetta's Kitchen
3. Reza's
4. Jamaican Me Crazy
5. Limones
3. Which restaurants have you previously eaten at?
type: checkbox
optsfrom: RESTAURANTS
3A. Which restaurant was your favorite?
type: radio
optsfrom: RESTAURANTS {if anyChecked($Q3,[id])}
Likewise, anyChecked
can be used with rowsfrom
in tables as a conditional decorator. To reference a table's row elements, we can combine the table ID with 'R[id]', for ex. '$Q7R[id]'. The anyChecked
function will evaluate each row from Q7 to see which should be included in Q8. Each row from COLORS that received a 1, 2, or 3 response in Q7 is then displayed in Q8.
setlist: COLORS
1. Red
2. Orange
3. Yellow
4. Green
5. Blue
7. How often do you wear the following colors?
type: radio table
1. Frequently
2. Occasionally
3. Rarely
99. Never
rowsfrom: COLORS
8. Why do you wear the following colors?
type: checkbox table
instruct: Select all that apply for each row.
1. It makes me happy to wear
2. I have a lot of clothes this color
3. The color looks good on me
4. I just like the color
rowsfrom: COLORS {if anyChecked($Q7R[id],1..3)}
Using option data
anyChecked
also accepts option data (custom data) when used in a condition
decorator on a list.
In this example, the [TYPE]
option data reference at anyChecked($Q5,[TYPE])
is substituted with the option data at the ANIMAL_GRPS list. This allows for each option in ANIMAL_GRPS to have its own anyChecked
condition. For example, the Mammals option needs the condition anyChecked($Q5,3,5..7)
to be "true" for it to be shown at Q5A.
setlist: ANIMALS
1. Ants
2. Bees
3. Cats
4. Crocodiles
5. Dogs
6. Elephants
7. Gorillas
8. Iguanas
9. Snakes
setlist: ANIMAL_GRPS
1. Mammals {{TYPE: 3,5..7}}
2. Reptiles {{TYPE: 4,8,9}}
3. Insects {{TYPE: 1,2}}
5. Which animals do you like?
instruct: Select all that apply.
type: checkbox
optsfrom: ANIMALS
5A. Which category of animals is your favorite?
type: radio
optsfrom: ANIMAL_GRPS [if anyChecked($Q5,[TYPE])}
Applying calculations using anyChecked
In the example below, anyChecked
uses arithmetic to dynamically assign an option's weight when it's paired with the selectby
tag and the weight
decorator. Checked options receive a value of '1', while those that aren't selected receive a '0'. These values are then used in the weight calculation.
If option 1, 2, or 3 is selected at Q6, the option is assigned a weight of '11' at Q6ASEL; if not, it receives a weight of '1'. QASEL's option 4, Hamster food, has a fixed weight of '5' and would only be shown to the respondent if none of the options 1-3 were selected. In the event of a tie, an option would be selected randomly.
6. Which pets do you have?
instruct: Select all that apply.
type: checkbox
1. Dog
2. Cat
3. Fish
99. None of these {exclusive: y}
6ASEL. Select product for deep dive
type: coded single select
selectby: weight
optsfrom: Q6.options -[99] { weight: 1 + 10*anyChecked($Q6,[id]) } { text: [text] food }
4. Hamster food { weight: 5 }
newpage
text: In this next section, we would like to ask you about <b>$QASEL_text</b>.
Comments
0 comments
Please sign in to leave a comment.