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

Equivalent of getChocieValue but for the choice text?

  • September 2, 2023
  • 5 replies
  • 213 views

Forum|alt.badge.img+10
  • Level 3 ●●●
  • 35 replies

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”?

Best answer by nroot

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

 

this.getQuestionInfo().Choices[1].Text

 

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

5 replies

Nam Nguyen
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+29
  • QPN Level 8 ●●●●●●●●
  • 1096 replies
  • September 2, 2023

@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


Forum|alt.badge.img+10
  • Author
  • Level 3 ●●●
  • 35 replies
  • September 2, 2023

@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?


Forum|alt.badge.img+10
  • Author
  • Level 3 ●●●
  • 35 replies
  • Answer
  • September 2, 2023

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

 

this.getQuestionInfo().Choices[1].Text

 

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


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • September 2, 2023

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

 

this.getQuestionInfo().Choices[1].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.


Forum|alt.badge.img+10
  • Author
  • Level 3 ●●●
  • 35 replies
  • September 2, 2023

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

 

this.getQuestionInfo().Choices[1].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().Choices[3].Text

returns “T3”, which is the desired behavior.