getArrayFromChoice( )

Convert the selected choice labels or codes from a multiple choice question (drop-down, radio button, check box) into an array.

Syntax

getArrayFromChoice(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):
  • "label": returns the selected choice control label. This is the default option if no option is provided.
  • "code": returns the selected choice control code if the question choice comes form a codelist.

Return value

This function returns an array with the labels of the selected choice control options. If no values are selected it returns an empty array.

Examples

Example 3-90 Given a dropdown (choice) control d2 with the labels "Yes" and "No" selected

// Return the first selected label from choice item dd2:
returngetArrayFromChoice(dd2)[0];
// returns "Yes"  

// Return the second selected label from choice item dd2:
return getArrayFromChoice(dd2)[1];
// Returns "No"

// Return the first selected code from choice item dd2:
return getArrayFromChoice(dd2, "code")[0];
// returns C1