The cvalue
(calculated value) tag is used on a question or variable to calculate and set a value. The value is set when the parent page is submitted. The tag input can contain any logical statement or Perl expression, and it uses the same formatting and syntax rules as standard Perl scripts. Usually, cvalue
is used to set a value to hidden variables.
Syntax
Put the cvalue
tag inside a question widget to set a value to that widget.
# In a question widget cvalue: Value, expression, or logical statement.
Note: The cvalue
tag is not designed for use with quotas or questions that use selectby
. cvalue
can be applied in coded number variables though.
Tags
The following tags can be included when using the cvalue
tag.
Tag | Description |
---|---|
invisible |
When set to 'y', hides the variable from the respondent. |
onload |
When set to 'y', executes the widget function on page load, rather than when the page is submitted (default). |
Examples
Assign value to background variable
Count of brands selected
Converting response to all caps
Aggregation variables with list functions
ALLSTEPS. VAR | Brands selected at any level of STEP1-STEP10 type: checkbox systemvar: y translate: n invisible: y optsfrom: BRANDS cvalue: listWhich(BRANDS,STEPNUMBER; anyChecked($QSTEP[STEPNUMBER:id],[BRANDS:id]); [BRANDS:id])
Calculating link-parameter-based variables
PANEL. Panel Identifier cvalue: $panel || 0 chapter: S translate: n invisible: y type: radio csentrycalc: y optsfrom: panel_list SAMP. Sample type type: radio translate: n invisible: y cvalue: url_param('smp') chapter: S 10. Rep. sample # 11. Rep 2 sample 20. Augment # 21. Augment #2 30. Over sample # 31. Over sample #2 # 40. Teen Sample # Has downstream logic - Do not use SAMP=40 for anything other than Teen Sample
"Return X" with logical references
The following can be used as an alternative to selectby
, though if not returning a value, selectby
is often a safer option.
X_MIN. type: hidden translate: n cvalue: <<END return 1 if (anyChecked($QX,1)); return 2 if (anyChecked($QX,2)); return 3 if (anyChecked($QX,3)); return 5 if (anyChecked($QX,4)); return 8 if (anyChecked($QX,5)); return 11 if (anyChecked($QX,6)); return 16 if (anyChecked($QX,7)); return 20 if (anyChecked($QX,8)); END
Comments
0 comments
Please sign in to leave a comment.