Scoring text entry in Loop & Merge | XM Community
Skip to main content

I have one question regarding how to score a "text entry". In my study, participants study image-name pairs and take a test. In the test, I show them the image, and also the first letter of the name, participants should input the missing part of the name in the text entry blank. I use loop & merge to do this. Please see the attached picture. Field 5 is the first letter of the name. Field 6 is the correct answer. I want to compare participants' input with Field 6 (the correct answer). But it seems that the scoring function in Qualtrics could not achieve this. The logic is clear. If the "text entry" equals to ${lm://Field/6}, then score = 1, if not, then score = 0. I think maybe a JavaScript is helpful. But I have no knowledge about how to write a JavaScript. Is there anyone who can help me? I will be very much appreciated.
PS. I can add a feedback using the display logic. If the input = ${lm://Field/6}, then display the text "you are right". I tried to think this question in another way: to calculate how many times this feedback is displayed. That equals to the correct score. But I can't find a way to calculate the display times of a question. Help!!!!
微信截图_20211216024817.png

Hi Tian, I believe one of our resident Qualtrics Wizards, TomG, has already provided a solution on another post that should address your query.
Cheers,
Cameron


HiCamM , thank you for your reply!
Actually I have tried the code in that post Loop & Merge with Scoring (text box) — Qualtrics Community, but unfortunately it did not work. I am sorry that I have no prior knowledge with JavaScript, please forgive me if I have make silly mistakes.
Referring to what Jiayi and TomG have discussed, I tried the following steps:
First, I set an embedded data field named CorrectNum, and set it to 0, before the Loop & Merge Block.
image.pngHere is what my loop and merge block looks like: for convenience I only include one case now
image.pngand it looks good
image.pngSecond, I add JavaScript in the "Text entry" part for scoring. Do I understand right?
image.pngAnd my JavaScript is based on Jiayi , here is the code:
Actually I did not understand the first line: why there is a field named EndLoop? Should I set the field "EndLoop" in my embedded data?
image.pngThird, I add a feedback block after the loop and merge block, and retrieve the embedded data "CorrectNum".
image.png
But it did not work, unfortunately.
Did I get something wrong? Could you please help me find out what I am missing?CamM Jiayi TomG I will be very much appreciated.
Thank you very much for your time!


Finally I figured this out based on Loop & Merge with Scoring (text box) — Qualtrics Community.
It is important to firstly set an embedded data named "score" and set its initially with 0.
image.png
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
  score = Qualtrics.SurveyEngine.getEmbeddedData('score');
var input = $(this.questionId).select('.InputText');
var answer = input p0].value;
var solution = "${lm://Field/6}";
if (answer === solution) {
score++;
}


  Qualtrics.SurveyEngine.setEmbeddedData("score", score);
});

Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/

});

Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});


Leave a Reply