How can I get the text of a selected choice in Javascript?

DRSKDRSK Community Member Qubie ✭

How can I get the text of a selected choice in Javascript?

I'm trying to get the answer-text of a multiple choice question before submitting it.
Based on the provided API, I tried:

foo = this.getSelectedAnswers(); 

This gives me an object but not the answer text. What I'm doing wrong?

Answers

  • flebfleb Czech RepublicCommunity Member Sage ✭✭✭

    Hi @DRSK ,
    I usually use something like this:

    Qualtrics.SurveyEngine.addOnload(function()
        {
    
            var selectedRecode; 
    
            this.questionclick = function(event, element) {
                if(element.type == "radio")
                    {selectedRecode = Number(this.getChoiceRecodeValue(this.getSelectedChoices()));
                     alert(selectedRecode);
                    }}
                    });
    
  • ahmedAahmedA IndiaCommunity Member Qubie ✭

    The following worked for me:

    Qualtrics.SurveyEngine.addOnload(function()
    {
        this.questionclick = function(event,element){
        if (element.type == 'checkbox')
        {
            var choiceNum = element.id.split('~')[2];
            var qNum = element.id.split('~')[1];
            var choiceRef = "#"+qNum+"-"+choiceNum+"-label > span";
            let choiceText = document.querySelector(choiceRef).innerHTML;
            Qualtrics.SurveyEngine.setEmbeddedData(choiceText,true);
            
           }
    
    
    
        }
    });
    
Sign In to Comment