Hello,
I would like to use loop and merge function in block with just one slider. The participant has to select number specified in loop and merge field "Select the number ${lm://Field/1} ". In these fields I have random number generator (${rand://int/1:100}). Is there a way, to validate, that participant selected the presented number? If yes, he/she can continue to next loop, if not, he/she can't continue or there is no next button. I was searching for answer, but I can't find solution. Thank you very much.
This was quite an interesting question. Add this to your JS:
Qualtrics.SurveyEngine.addOnReady(function () {
let quest = this,
ip = quest.questionContainer.querySelector(".ResultsInput"),
val = "${lm://Field/1}",
nb = document.querySelector("#NextButton");
nb.hide();
ip.onchange = function () {
if (ip.value == val) nb.show();
else nb.hide();
};
});
However, if this is an attention test, I think its a bit too difficult. Demo
Thank you very much for your reply. I don't know why, but it does not work in my case.
At first I thought it is because other script - I want to have custom button to exit loop&merge. But it does not work even without that script. Do you know why? Also, can use both scripts?
https://stackoverflow.com/questions/25766238/prematurely-exiting-a-loop-and-merge-block-in-qualtrics
I think what is happening is that the random number is being intialized twice. So there's a difference between the value being fed to the JS and the one to HTML.
Assign
valto
parseInt(quest.innerText.replace(/\\D/gm, ""))and see if it works.
https://www.qualtrics.com/community/discussion/comment/37433#Comment_37433I changed It does not work
val = "${lm://Field/1}"
to
val = parseInt(quest.innerText.replace(/\\D/gm, ""))
and it does nothing
I wonder why it works in your demo.
I'm sorry to bother you. I will probably have to do some "me-friendly" manual setup..
Thank you very much for your help. I lowered my expectations and used real numbers, it works just fine.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.