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

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!

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.


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


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!


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.


@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(", "));
});

 


Works like a charme. Thank you very much!


Leave a Reply