The contains
function checks a collection for a given single value. It returns "true" if the value is found, and "false" otherwise. The notContains
function does the opposite, returning "false" if the value is found and "true" if it is not.
8. Which of the following people have you purchased vitamins & supplements for in the past 12 months?
instructions: Please select all that apply
type: checkbox
1. Myself
2. A baby (under 3 years old)
3. A family member who is 3-9 years old
4. A family member who is 10-17 years old
5. A family member who is 18-65 years old
6. A family member older than 65 years old
97. Other ____________ {autoother placeholder: Please specify; size: 12; desc: Other}
set list: NEED_STATES
1. Strengthening Bones & Joints
2. Managing back pain
3. Pregnancy & Conception
4. Skin, Hair and Nails
5. Weightloss
6. Sleep & Relaxation
97. Other ___ {autoother placeholder: Please specify; size: 12; desc: Other}
23. Which of the following health needs does this person use vitamins & supplements for?
instructions: Please select all that apply
type: checkbox
optsfrom: NEED_STATES {if notContains([id],3) or (contains([id],3) and anyChecked($Q8,1))}
In the example above, Q23 references the NEED_STATES list. The condition states that option 3 (Pregnancy & Conception) should never be shown, unless the respondent chose options 2, 3, or 4 at Q8.
Details
- To create the input, insert the item to match, followed by a comma and the collection to check against. Surround the input with parentheses, e.g.,
contains([id],1,2)
. - The item to match can be the option data placeholders
[id]
or[text]
. - The item to match can be placed within a block, within a conditional "if" statement, and also can be used with the
weight
decorator. - The collection to check against supports syntax with ranges, e.g.,
contains([id],1..6)
. - Both
contains
andnotContains
functions work anywhere Perl is accepted.
Additional examples
Checking text strings
Strings can also be used as inputs, but they must be surrounded by single quotes. In the example below, Q1 will display the options from the FRUITLIST that contain the referenced texts. Then, Q2 will display options from the same list if they do not contain the referenced texts.
setlist: FRUITLIST
1. Monkey
2. Banana
3. Lemon
4. Watermelon
1. Which options in the list are fruits?
type: radio
optsfrom: FRUITLIST {if contains('[text]','Banana','Lemon', 'Watermelon')}
2. Which option in the list is not a fruit?
type: radio
optsfrom: FRUITLIST {if notContains('[text]','Banana','Lemon', 'Watermelon')}
Using 'contains' with selection weighting
The contains
and notContains
functions are often used with variables using selectby: weight
. In the example below, Q2SEL prioritizes 'Campbell's soup' (ID 1) with the highest weight of 1000, followed by 'Secondary Brands' (IDs 3, 4, 5, 7) with a weight of 500, and lastly 'Other Brands' (IDs 2, 6) with no weight assigned.
Q2SEL checks Q1 selections:
- If ID 1 is selected, it gets a weight of 1000.
- If IDs 3, 4, 5, or 7 are selected, they get a weight of 500.
- IDs 2 and 6 have no weight and are selected last.
setlist: BRANDS
1. Campbell's soup
2. Other Brand Healthy Choice
3. Secondary Brand Progresso
4. Secondary Brand Trader Joe's
5. Secondary Brand Annie's
6. Other Brand Roa's
7. Secondary Brand Amy's Kitchen
1. Which brands have you used?
type: checkbox
optsfrom: BRANDS
2SEL. Two Primary brands
type: coded multiple select
maxgroups: 2
selectby: weight, counts
optsfrom: Q1 {weight: (contains([id],1)*1000) + (contains([id],3..5,7)*500)}
Comments
0 comments
Please sign in to leave a comment.