Get recode value of two questions | XM Community
Skip to main content
Solved

Get recode value of two questions

  • November 24, 2021
  • 2 replies
  • 345 views

ManfredBM
Level 5 ●●●●●
Forum|alt.badge.img+35

Hi,
since I'm quite new to JS (and especially to JS in Qualtrics), I'm struggling with the following task:
When the page unloads, I want to do some custom calculation and save the result in an embedded data field. Since the calculation is rather complex, I can't use the math operations in survey flow.
I guess I know how to do the calculation and how to store the embedded data, but how can I best retrieve the recode values of an answered question (Question IDs are known: QID7 // QID8)?
Some additional information: QID7 and QID8 are both Multiple Choice (single answer!) questions displayed on the same page.
Thanks!
Manfred

Best answer by StephH72

Hi Manfred,
I can only get it to work with a pagebreak between the two questions so hopefully someone can improve on this answer. But this is the code I have so far which works if the questions are on 2 pages:
Qualtrics.SurveyEngine.addOnPageSubmit(function() 
{
var Answer1 = "${q://QID7/SelectedChoicesRecode}";
var Answer2 = this.getChoiceAnswerValue();
var FinalAnswer = parseInt(Answer1) + parseInt(Answer2);
Qualtrics.SurveyEngine.setEmbeddedData( 'FinalAnswer ', FinalAnswer );
});

I hope this helps a bit :)
Steph

2 replies

StephH72
Level 2 ●●
Forum|alt.badge.img+16
  • Level 2 ●●
  • Answer
  • November 24, 2021

Hi Manfred,
I can only get it to work with a pagebreak between the two questions so hopefully someone can improve on this answer. But this is the code I have so far which works if the questions are on 2 pages:
Qualtrics.SurveyEngine.addOnPageSubmit(function() 
{
var Answer1 = "${q://QID7/SelectedChoicesRecode}";
var Answer2 = this.getChoiceAnswerValue();
var FinalAnswer = parseInt(Answer1) + parseInt(Answer2);
Qualtrics.SurveyEngine.setEmbeddedData( 'FinalAnswer ', FinalAnswer );
});

I hope this helps a bit :)
Steph


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

Thanks, StephH72!
As a last resort I'll have to insert a page break.
Or I just run the calculation on the first question of the next page. Certainly not the best coding style, though.