Equivalent of getChocieValue but for the choice text? | XM Community
Solved

Equivalent of getChocieValue but for the choice text?

  • 2 September 2023
  • 5 replies
  • 82 views

Userlevel 3
Badge +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”?

icon

Best answer by nroot 2 September 2023, 23:22

View original

5 replies

Userlevel 7
Badge +20

@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

Userlevel 3
Badge +10

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

Userlevel 3
Badge +10

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.

Userlevel 7
Badge +27

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.

Userlevel 3
Badge +10

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.

 

 

Leave a Reply