Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
Qualtrics: Using Javascript to Score Questions Inside a Loop/Merge Block

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

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") 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!