getStringFromChoice( )
Convert selected choice labels or codes from a multiple-choice question (drop-down, radio button, check box) into a comma-separated string.
Syntax
getStringFromChoice(variable, [option])
Parameters
Parameter | Required/Optional | Description |
---|---|---|
variable |
Required | Rule variable, corresponding to a choice type field, that you want to retrieve. |
option |
Optional | Defines which element of a choice control value to return
(including quotes is required):
|
Return value
This function returns a comma-separated string with the labels of the selected choice control options. If no values are selected it returns an empty string.
Examples
Example 3-92 Given a dropdown (choice) control dd2 with labels "Yes" and "No" selected
// return all selected labels from choice
return getStringFromChoice(dd2);
// if single label is selected, returns "label1"
// If multiple labels are selected, returns "label1,label2"
// return a code from choice:
return getStringFromChoice(dd2, "code");
// returns C1
Example 3-93 Convert a codelist term used as a coding target item into a string value
You can use an expression to convert a coding target using a choice question with a related specify text question.
For this example, you have designed a choice question with an option for Other. When the site user chooses Other, they are prompted to enter descriptive text into another question. This expression code allows you to combine predefined choice text and the Other specified text into a single question that is then tagged as the context item for coding. This is helpful because you can only tag a single question as the given context item.
if (ROUTE !== null)
{
return (ROUTESP === null ? getStringFromChoice(ROUTE) : (getStringFromChoice(ROUTE) + ': ' + ROUTESP));
}
else
{
return '';
}
Parent topic: Multiple choice question functions