0

I have a multiple choice question (Yes/No) where Yes correlates to a score of 0 and No correlates to a score of 1. I've used the "Recode Values" feature to set Yes to 0 and No to 1. This is inside a loop/merge block, so I cannot use the Scoring feature or Embedded Data/Branching in Survey Flow.

My code currently looks like this:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var answer = jQuery("#"+this.questionId+".q-checked").val();
Qualtrics.SurveyEngine.setEmbeddedData('answer', answer);
if(answer = 0)  Qualtrics.SurveyEngine.setEmbeddedData('mmm', '0');
if(answer = 1)  Qualtrics.SurveyEngine.setEmbeddedData('mmm', '1');
});

I have also tried:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var answer = this.questionContainer.querySelector(".q-checked").nextElementSibling.innerText;
Qualtrics.SurveyEngine.setEmbeddedData('answer', answer);
if(answer = 0)  Qualtrics.SurveyEngine.setEmbeddedData('mmm', '0');
if(answer = 1)  Qualtrics.SurveyEngine.setEmbeddedData('mmm', '1');
});

Inside the same block after this question, I have a page break and then two questions with display logic. If they answer Yes/get a score of 0 on the preliminary question, it should display Question A. If they answer No/get a score of 1 on the preliminary question, it should display Question B.

My code seems to set their score to 1 and display Question B no matter if they answer Yes or No to the preliminary question.

Thank you in advance for any help.

1 Answer 1

0

There are three issues with your code. The first is that you are missing a space before .q-checked in your jQuery selector. It should be:

var answer = jQuery("#"+this.questionId+" .q-checked").val();

The second issue is that the value (choiceid) is not the same thing as the recode. You can either use choiceids (probably 1=Yes and 2=No) or use the Qualtrics JS API to get the recode associated with the value.

The third issue is that your comparisons are incorrect. They should look like:

if(answer == "0") 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.