Use an addOnPageSubmit JavaScript function to check the value of the text input against the correct value from the loop field, and if it matches increment an embedded data field that contains your "score".
>
@TomG said:
> Use an addOnPageSubmit JavaScript function to check the value of the text input against the correct value from the loop field, and if it matches increment an embedded data field that contains your "score".
Unfortunately this method didn't work for the loop and merge block when I tried, likely due to the fact that the embedded data field is set at the end of the block, i.e., after all rounds in the loop and merge block have been gone through.
>
@Jiayi said:
> >
@TomG said:
> > Use an addOnPageSubmit JavaScript function to check the value of the text input against the correct value from the loop field, and if it matches increment an embedded data field that contains your "score".
>
> Unfortunately this method didn't work for the loop and merge block when I tried, likely due to the fact that the embedded data field is set at the end of the block, i.e., after all rounds in the loop and merge block have been gone through.
The embedded data field updates as soon as the page is submitted. It works when I try it. Post your code.
>
@TomG said:
> >
@Jiayi said:
> > >
@TomG said:
> > > Use an addOnPageSubmit JavaScript function to check the value of the text input against the correct value from the loop field, and if it matches increment an embedded data field that contains your "score".
> >
> > Unfortunately this method didn't work for the loop and merge block when I tried, likely due to the fact that the embedded data field is set at the end of the block, i.e., after all rounds in the loop and merge block have been gone through.
>
> The embedded data field updates as soon as the page is submitted. It works when I try it. Post your code.
Here's the JavaScript method I use (which unfortunately didn't work):
First, create an embedded data field before the loop and merge block called "CorrectNum" and set it to 0. Next, in the JavaScript editor at the task page in the loop and merge block, add code to the Qualtrics.SurveyEngine.addOnload(function(){}) as below:
!
Then use the embedded data field "CorrectNum" in the block after the loop and merge block to show feedback to respondents.
I also tried to define correctNum globally in the Header and then increment the variable within the loop and merge block, which didn't work either. I suspect that variables need to be defined within the question page to be called.
Any clues? Thanks!
The biggest issue is that you are doing an addOnload. That happens when the page loads, so the respondent hasn't done anything yet, and the input is blank. You should be using addOnPageSubmit. BTW, the class name for a text input is InputText.
>
@TomG said:
> The biggest issue is that you are doing an addOnload. That happens when the page loads, so the respondent hasn't done anything yet, and the input is blank. You should be using addOnPageSubmit. BTW, the class name for a text input is InputText.
Thanks a lot! It turns out that it is the issue with "addOnload" and I should be using "addOnPageSubmit".
I tried applying these instructions to a similar project, but the scoring feature doesn't work. Any ideas to what I might be missing?
The project involves solving arithmetic problems, receiving feedback, and then showing the total number correct at the end of the loop and merge.
Flashcards.qsf
Hello,
How would you implement this with a multiple choice question?
Thanks