Getting recoded value of single choice question with javascript | XM Community
Skip to main content
Solved

Getting recoded value of single choice question with javascript

  • November 26, 2021
  • 6 replies
  • 710 views

While I am able to get the (not recoded) value of a chosen answer with

this.getChoiceAnswerValue()
, I just don't get the recoded values. Both lines of following code result in empty variables:
var value2 = this.getChoiceRecodeValue();
var value3 = this.getChoiceRecodeValue(this.getSelectedChoices());
Any help much appreciated!

Best answer by ManfredBM

Hi novern ,
this works for me:
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
  var value = this.getChoiceRecodeValue(this.getSelectedChoices());
  alert("Recode Value: " + value);
});
The code only works in the "addOnPageSubmit" section. Not in "addOnUnload".

Hope that helps.

6 replies

ManfredBM
Level 5 ●●●●●
Forum|alt.badge.img+35
  • Level 5 ●●●●●
  • Answer
  • November 29, 2021

Hi novern ,
this works for me:
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
  var value = this.getChoiceRecodeValue(this.getSelectedChoices());
  alert("Recode Value: " + value);
});
The code only works in the "addOnPageSubmit" section. Not in "addOnUnload".

Hope that helps.


  • Author
  • December 1, 2021

ManfredBM Yes, that totally helps, thank you! The problem was I placed it in "addOnUnload".


Forum|alt.badge.img+4
  • Level 1 ●
  • June 21, 2023

I’m currently struggeling with this issue. The mentioned solution keeps giving me an empty value.

Here is my code, any suggestions?

Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
    var label        = document.getElementsByClassName("ExportTag").item(0);
    var qId           = label.innerHTML;
    var choiceId   = this.getChoiceRecodeValue(this.getSelectedChoices());

    alert('Question ID: '+qId+' / Choice ID: '+choiceId);

});

Thanks in advance!


Forum|alt.badge.img+4
  • Level 1 ●
  • June 22, 2023

I’m currently struggeling with this issue. The mentioned solution keeps giving me an empty value.

Here is my code, any suggestions?

Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
    var label        = document.getElementsByClassName("ExportTag").item(0);
    var qId           = label.innerHTML;
    var choiceId   = this.getChoiceRecodeValue(this.getSelectedChoices());

    alert('Question ID: '+qId+' / Choice ID: '+choiceId);

});

Thanks in advance!

Edit: Figured out that it works for single answer only, but I need it for multiple answer questions as well! Thanks.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • June 22, 2023

@4dshopper - You need to loop through the selected choices:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var qobj=this, recodes=[];
jQuery.each(qobj.getSelectedChoices(), function(i,cid) {
recodes.push(qobj.getChoiceRecodeValue(cid));
});
alert("Question ID:"+qobj.questionId+" / Recodes:"+recodes.join(", "));
});

 


Forum|alt.badge.img+4
  • Level 1 ●
  • June 22, 2023

Works like a charme. Thank you very much!