Equivalent of getChocieValue but for the choice text? | XM Community
Skip to main content

For a multiple choice question, my impression is that getChoiceValue() returns whether or not the option is selected. Is there a function to instead return the text value of the chocie? For example if I have choices “East”, “West”, “North”, “South”, and I did fn(2), it would return “West”?

@nroot Try this

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

And pip-text ${e://Field/choiceText} see if it works


@nroot Try this

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

And pip-text ${e://Field/choiceText} see if it works

 

This returns the text of the clicked choice - what I meant was to be able to query the text of any choice, by feeding a function the number of the choice. So I want to be able to query fn(1), fn(2), fn(3), etc., the way I can query getChoiceValue(1), getChoiceValue(2), etc. How do I get the elements without relying on an onclick event?


Ah, figured it out. In case someone else needs:

 

this.getQuestionInfo().Choicess1].Text

 

Replace “1” with the choiceId of whatever choice you need the text from.


Ah, figured it out. In case someone else needs:

 

this.getQuestionInfo().Choicess1].Text

 

Replace “1” with the choiceId of whatever choice you need the text from.

Or the shorter:

this.getTextValue(1);

where 1 is the choice id.


Ah, figured it out. In case someone else needs:

 

this.getQuestionInfo().Choicess1].Text

 

Replace “1” with the choiceId of whatever choice you need the text from.

Or the shorter:

this.getTextValue(1);

where 1 is the choice id.

 

That’s not quite right, yours returns the text value of the (optional) text box. E.g. in this setup:

 

 

this.getTextValue(3)

returns “asdf”

 

this.getQuestionInfo().Choiceso3].Text

returns “T3”, which is the desired behavior.

 

 


Leave a Reply