The dynamic value
function sets a question's value based on another question or variable. The questions or variables controlling the value that is applied, as well as the target question itself, can be any question type. All question references can be located on the same survey page, different survey pages, or a combination of both. Because of this flexibility, dynamic value
can be used for simple auto-coding of closed-end values, respondent-facing math calculations, and so on.
dynamic value
is a standalone widget, or a set of tags inline within another widget.
Syntax
# Widget dynamic value question: Question ID Here value: Value to set, can include expression to evaluate # Inline tag dynamicvalue: Value to set to parent widget, can include expression to evaluate
Tags
Since dynamic value
can be a standalone widget or used as a tag inline within another widget, the supporting tags change slightly depending on which method you choose. In the table below, notice that if dynamic value
is its own widget, the condition
tag can be applied. However, if it is being used as a tag, the condition
tag specifically for dynamic value
becomes dynamiccondition
.
Widget | Inline | Description |
---|---|---|
question |
The question ID where you'll apply the value. | |
condition |
dynamiccondition |
An expression (conditional "if" statement); if the expression evaluates to "true," the value will be applied to the question or table widget. |
value |
dynamicvalue |
The value being set to the question or table widget. The value tag input can be another variable, expression, or string. |
lock |
dynamiclock |
Setting this tag prevents the respondent from changing the actively set values. Both |
table |
Allows for a table target and refers to table ID. This creates a new dynamic value widget for each matching question in the table, using the above settings. With table set, the ID of the row, column, or question may be put into any of the expressions (value, option, condition, filter) using __RID__ , __CID__ , or __ID__ syntax |
|
filter |
dynamicfilter |
Only applicable if questions in a table are being set. This is used to filter the questions in the table (excluding autoothers). All __(ROW|COL|ID)__ references will be replaced before evaluation. |
Note: The following tags can no longer be used with dynamicvalue
:
-
option
/dynamicoption
unset_on_change
Note that dynamic options
is still available.
Widget examples
'value' tag
The value
tag accepts other variables as an input, rather than a string ('this is a string') or an expression ('1 + 5').
Using arrays with 'value'
The value
tag also accepts an array. This is useful for coding (setting a value to) multi-select questions. When targeting a checkbox question with dynamicvalue
, be aware that any previous data stored in the checkbox question or variable will be cleared, and only the value
specified will remain.
In this example, the answer from Q3 plus option 4 will be set to Q4.
'condition' tag
The condition
tag evaluates a Boolean statement. If the statement returns true, then the value is applied to the question specified. Here, if option 1, 2, or 3 is selected at Q3A, then the answer from Q3A plus option 4 will be set to Q4A.
'lock' tag
The lock
tag prevents respondents from modifying the target question. Though this works on all question types, the most common usage for this is with text fields - when the text field performs a calculation which helps respondents answer a question, and/or when the calculation itself must be a given number (e.g., 100%, 10 points, etc.) in order for the question to successfully validate.
The above summing row example can be written to dynamically reference all table rows with __ALLROWS__
reference if it is written inline. See additional examples, calculating row and column totals for more information.
Table and filter
The table
and filter
tags work in tandem, and they allow dynamicValue
to work within tables. When a table
tag is used, it signifies that the target field is within a table, and the filter
tag allows you to specify the target cells within the table. The condition
and filter
tags, when used within a table-focused dynamicValue
widget, accept __RID__
and __CID__
references, as well as __ALLROWS__
and __ALLCOLS__
references.
Tip! Since dynamicvalue
mainly uses JavaScript for its calculation, some undocumented functions may help experienced users. Try using .toFixed()
to limit the decimal precision of the resulting value. For example, to limit a respondent's input to two decimal places, use the following:
dynamicvalue: ($QP2R__RID__C1 * $QP1PRICE__RID__).toFixed(2)
Comments
0 comments
Please sign in to leave a comment.