getAnswerName()

The getAnswerName() function (client-side) retrieves the name of the specified answer or the name of the first selected answer for a question. The name corresponds to the value in the Name field on the answer record.

Syntax

Use these syntax formats for the getAnswerName() function:

  • To retrieve the name of the first selected answer for a question:

                    getAnswerName('QUESTION_CODE'); 
    
                  
  • To retrieve the name of a specific answer:

                    getAnswerName('QUESTION_CODE/ANSWER_CODE'); 
    
                  

Return Value

The getAnswerName() function returns the answer name as a string.

            'Name' 

          

Parameters

Note:

Either the question code or the combination of question and answer codes is required.

The getAnswerName() function can take the following parameters:

  • QUESTION_CODE (string) - Specifies the code of the question to which the answer belongs.

  • QUESTION_CODE/ANSWER_CODE (string) - Specifies the 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 getAnswerName() function.

Retrieving a Specific Answer Name

This example retrieves the name associated with the answer that has the code SERIESC and belongs to the question with DESKTOP as a code.

              const name = getAnswerName('DESKTOP/SERIESC');
console.log(name); 

            

The returned name may be:

              Desktop Series C - Basic 

            

Retrieving the Name for the First Selected Answer

The example retrieves the name associated with the first selected answer for the "Select desktop series" question, which has DESKTOP as a code.

              const name = getAnswerDesc('DESKTOP');
console.log(name); 

            

Suppose the question has the following answers:

  1. Series A (name "Desktop Series A - Premium")

  2. Series B (name "Desktop Series B - Advanced")

  3. Series C (name "Desktop Series C - Basic")

If a user selects "Series C" and "Series B", the returned name will be:

              Desktop Series C - Basic 

            

Related Topics

General Notices