getAnswerLabel()
The getAnswerLabel() function (client-side) retrieves the label of a specific answer or the label of the first selected answer for a question. The label matches the value of the Label field on the answer record.
Syntax
Use these syntax formats for the getAnswerLabel() function:
-
To retrieve the label of the first selected answer for a question:
getAnswerLabel('QUESTION_CODE'); -
To retrieve the label of a specific answer:
getAnswerLabel('QUESTION_CODE/ANSWER_CODE');
Return Value
The getAnswerLabel() function returns the answer label as a string.
'Label'
Parameters
Either the question code or the combination of question and answer codes is required.
The getAnswerLabel() function accepts the following parameters:
-
QUESTION_CODE(string) - Specifies the code of the question to which the answer belongs. -
QUESTION_CODE/ANSWER_CODE(string) - Specifies he combination of question and answer codes that identifies the answer. You can find the codes in the Code field on the corresponding records.
Examples
The following examples show how to use the getAnswerLabel() function.
Retrieving a Specific Answer Label
This example retrieves the label associated with the answer that has code BLUE and belongs to the question with the code COLOR.
const label = getAnswerLabel('COLOR/BLUE');
console.log(label);
The returned label may look like this:
Navy Blue
Retrieving the Label for the First Selected Answer
The example retrieves the label associated with the first selected answer for the "Select color" question, which has the code COLOR.
const label = getAnswerLabel('COLOR');
console.log(label);
Suppose the question has the following answers:
-
Navy Blue (code BLUE)
-
Beige (code BEIGE)
-
Gray (code GRAY)
If a user selects "Navy Blue" and "Beige", the returned label may be:
Navy Blue