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 used in a single line of code for simpler needs. The same example above could also use the following syntax, attached to Q1:set: Q2 {value: $Q1} {condition: countChecked($Q1) == 1}
.
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 set value
punches a specific option at QCOLORTEMP. If the condition is met (i.e., certain colors are selected), the corresponding option at QCOLORTEMP is set to 1
(selected).
set list: COLORS
1. Red
2. Green
3. Blue
4. Cyan
5. Magenta
6. Yellow
7. Orange
8. Purple
9. Brown
10. Gray
11. Black
12. White
1. Which colors do you like?
type: checkbox
optsfrom: COLORS
set value
question: QCOLORTEMP
option: 1
value: 1
condition: anyChecked($Q1,1,6,7,9)
set value
question: QCOLORTEMP
option: 2
value: 1
condition: anyChecked($Q1,2,3,4,5,8)
set value
question: QCOLORTEMP
option: 3
value: 1
condition: anyChecked($Q1,10,11,12)
COLORTEMP. Color temperature of favorite color.
type: checkbox
invisible: y
1. Warm
2. Cool
3. Neutral
Using the single line approach with the 'set' tag
You can set a value with a single line of code using the set
tag along with option
, value
, and condition
decorators.
- Place the
set
tag on the source question. - Specify the target question as the input.
- Use
value
to define what to store.- For radio questions, use
$QX
as the value, where X is the question where the value being coded is found. - For checkbox questions, use
1
for "selected" and use theoption
decorator to then specify which option to update.
- For radio questions, use
- Use
condition
to trigger when the value should be set.
The same example above can be written in a more concise manner. For example, if Q1 has options 1, 6, and 11 selected, QCOLORTEMP will automatically punch option 1 "Warm" and option 3 "Neutral."
set list: COLORS
1. Red
2. Green
3. Blue
4. Cyan
5. Magenta
6. Yellow
7. Orange
8. Purple
9. Brown
10. Gray
11. Black
12. White
1. Which colors do you like?
type: checkbox
optsfrom: COLORS
set: QCOLORTEMP {option: 1} {value: 1} {condition: anyChecked($Q1,1,6,7,9)}
set: QCOLORTEMP {option: 2} {value: 1} {condition: anyChecked($Q1,2,3,4,5,8)}
set: QCOLORTEMP {option: 3} {value: 1} {condition: anyChecked($Q1,10,11,12)}
COLORTEMP. Color temperature of favorite color.
type: checkbox
invisible: y
1. Warm
2. Cool
3. Neutral
Note: The question or variable being punched should not include a condition
tag, decorator, or built-in condition (e.g., coded variables), as this will override the condition set by set value
.
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
Comments
0 comments
Please sign in to leave a comment.