The set value
widget assigns a value to a specified question or variable. It's typically used to store values for skipped questions.
1. Select any activities you have tried before.
type: checkbox
1. Running
2. Walking
3. Lifting weights
4. Biking
5. Playing sports
6. Swimming
7. Yoga
set value
question: Q2
value: $Q1
condition: countChecked($Q1) == 1
2. Select your favorite of these activities.
show if: countChecked($Q1) > 1
type: radio
optsfrom: Q1
Details
- The
set value
widget is flexible and powerful. It can be used to assign a value to any question or variable type. For assistance with complex setups, contact Support or send an email to help@intellisurvey.com. - A
set value
widget requires, at minimum, thequestion
andvalue
tags to assign the correct value to the specified question. - The
question
tag can accept a question ID (e.g., 'Q2') or use Perl syntax to construct a complex ID, such as a table row (e.g., '{'Q4R' . get_first_answer('Q3')}') as its input. - The
value
tag can accept either a static number, such as '1', or a dynamic value, such as '$Q1'. - When setting a value to a checkbox question, use the
option
tag to specify which answer option should be coded. Not applying theoption
tag could result overwriting existing data or recording incorrect data. - The
condition
tag can be added to apply a logical statement. If true, it triggers theset value
widget. Without this tag, the value is always set. -
set value
can also be applied as an element decorator usingset question
syntax.
Tip! The autocode
tag is a newer method for setting a value to a closed-ended question when only one option has been selected in a previous question, as illustrated in the example above.
Additional tags
There are a few tags that are often added to a set value
widget.
Tags | Description |
condition |
Evaluates a logical statement, also known as an "if statement." If the statement is true, the |
onload |
Executes the set value when the page loads, instead of when the page is submitted. |
option |
Specifies the option ID in the question that should be automatically coded. |
Additional examples
Setting a single value to a checkbox question
When setting a value for a multiselect (checkbox) question, you should specify both the option ID and the value. Similar to how a checkbox question appears in an Excel export — where each option ID has its own column, and values are '1' for selected and '0' for not selected — you must follow the same pattern.
- First, specify the question ID.
- Then, identify the option ID to be coded.
- Finally, assign a value of '1' for "selected."
If the option
tag is omitted, not applying the option
tag could result overwriting existing data or recording incorrect data.
In the example below, each attention check has a set value
programmed. If an attention check is failed (e.g., QATT1
), the set value
codes the QATTCHECKS
variable with '1' for the corresponding option.
ATT1. For quality purposes please select the response below that does not belong in the set:
type: radio
randomize: y
1. Red
2. Blue
3. Train
4. Green
set value
question: QATTCHECKS
option: 11
value: 1
condition: noneChecked($QATT1,3)
ATTCHECKS. Attention checks
type: checkbox
invisible: y
translate: n
11. QATT1 - <> Train
12. QATT2 - <> 12
3. QTOPIC_CHECK - NOT correct topic
Coding and skipping a sum-to-100 table
In the example below, if the respondent selects only one option at Q3 they skip Q4. We use get_first_answer
to retrieve the selected option ID, which is then combined with 'Q4R' to construct the full question ID, for example 'Q4R3'. The specified row is then set to 100. A second set value
ensures the "total" row is also set to 100.
3. Select any activities you have tried before.
type: checkbox
1. Running
2. Walking
3. Lifting weights
4. Biking
5. Playing sports
6. Swimming
7. Yoga
set value
question: {'Q4R' . get_first_answer('Q3')}
value: 100
condition: countChecked($Q3) == 1
set value
question: Q4RSCT
value: 100
condition: countChecked($Q3) == 1
4. When you do activities, what percentage of time do you spend doing each one?
type: integer table
range: 0-100
show column total: Total % {total: 100}
postfix: %
rowsfrom: Q3
Combining two tables' data into one
The tables are split for a better respondent experience, but the client needs a single table for analysis. A block loops through a set value
widget, using the value
tag to pull answers from Q7_1 or Q7_2. If a value is found, it is stored in the hidden table for that row.
set list: BRANDS
optsfrom: series[1..18]
set list: 1TO7
optsfrom: series[1..7]
7_1. Please rate each brand on a scale on 1 to 7, where 1=most likable and 7=least likable.
systemvar: y
type: radio table
headings: Most, Least
optsfrom: series[1..7]
rowsfrom: BRANDS [1..9] {text: Brand [id]}
7_2. Please rate each brand on a scale on 1 to 7, where 1=most likable and 7=least likable.
systemvar: y
type: radio table
headings: Most, Least
optsfrom: series[1..7]
rowsfrom: BRANDS [10..18] {text: Brand [id]}
block:<<BLKSV7
set value
question: Q7R%%ID%%
value: $Q7_1R%%ID%% || $Q7_2R%%ID%%
BLKSV7
list: BRANDS
7. Hidden variable that receives the combined data from the set value block, BLKSV7.
type: radio table
invisible: y
optsfrom: series[1..7]
rowsfrom: BRANDS
Tip! The newer page every
tag is preferred to split tables across multiple pages.
Using 'onload'
In the example below, the set value
uses the onload
tag to automatically assign the value '1' to the first row ("Self") as soon as the page loads. Without this tag, the value would only be set when the table is submitted, which wouldn't be helpful for the respondent.
set value
question: QC3R1
value: 1
onload: y
C3. Please provide how many of each of the following live in your household.
instructions: Please count yourself.
type: integer table
if blank: 0
range: 0-20
rows:
1. Self
2. Spouse/Partner
3. Children under age 18
4. Children age 18-22
5. Children age 23 or older
6. My parents or my spouse’s or partner’s parents
7. Other adults
show column total: Total number in household
validation: $QC3R1 == 1
message: Please enter '1' for Self
As an element decorator
You can also use set value
as an inline element decorator. Place a set of single curly brackets after the list option and use the syntax set question
. Specify the question or variable (e.g., 'QGOLFXTYPE') followed by the parameter 'value' and the desired value (e.g., '1'). In the example below, if a respondent selects options 1, 2, or 3 at Q5, QGOLFXTYPE will be set to option 1, "public."
5. How would you describe the <b>golf course</b> you work for?
type: radio
randomize: y
1. Municipal course {set question: QGOLFXTYPE value: 1}
2. Other public / daily fee course {set question: QGOLFXTYPE value: 1}
3. Semi-private course {set question: QGOLFXTYPE value: 1}
4. Private course / country club {set question: QGOLFXTYPE value: 2}
97. Other {autoother: y} {anchor: y}
GOLFXTYPE. Golf type
type: radio
invisible: y
dvalue: 0
0. Null
1. Public
2. Private
Comments
0 comments
Please sign in to leave a comment.