Retrieving selected choice in slider questions using JS | XM Community
Skip to main content
Solved

Retrieving selected choice in slider questions using JS

  • August 18, 2024
  • 5 replies
  • 129 views

Forum|alt.badge.img+2

I’m having trouble extracting the selected choices in slide questions. 

For multiple choice questions, I was able to use this.getSelectedChoices in addOnPageSubmit. However, using the same thing for slider questions gives me the value of 4 regardless of what values I choose in preview. I tried getChoiceValue too, but it return null regardless of what I choose. 

My goal is to compare the selected answer with my correct answer, which determines what happens next in the survey for this participant. 

Has anyone dealt with this before? 

Best answer by TomG

@CindyJ,

This works for me:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
console.log(this.getChoiceAnswerValue(1));
});

Perhaps the choiceid of the slider isn’t 1.

5 replies

chackbusch
QPN Level 5 ●●●●●
Forum|alt.badge.img+22
  • QPN Level 5 ●●●●●
  • 415 replies
  • August 18, 2024

@CindyJ You may check this comment.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • August 18, 2024

@CindyJ - Use this.getChoiceAnswerValue(1) where 1 is the choiceid of the first slider.


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 7 replies
  • August 20, 2024

@CindyJ - Use this.getChoiceAnswerValue(1) where 1 is the choiceid of the first slider.

Right now, I have 

But it still gives me null:

Does anyone have any idea why this is? Did I fail to submit the selected answer?


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • Answer
  • August 20, 2024

@CindyJ,

This works for me:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
console.log(this.getChoiceAnswerValue(1));
});

Perhaps the choiceid of the slider isn’t 1.


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 7 replies
  • August 21, 2024

@CindyJ,

This works for me:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
console.log(this.getChoiceAnswerValue(1));
});

Perhaps the choiceid of the slider isn’t 1.

I opened a different survey and started over and your code is working now! There as probably something wrong with my settings for the slider earlier. 

Thank you so much!!