I want to ask if anyone knows, in javascript code, how to refer to a text entry response/input in a Loop and Merge block. I got to know the corresponding format when there is no Loop and Merge from this very useful post Qualtrics: Javascript to prevent saving entry from Text Box. See the code below:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place Your Javascript Below This Line*/
var currentQuestionID = this.getQuestionInfo().QuestionID
var input = $("QR~"+currentQuestionID);
$('NextButton').onclick = function (event) {
input.value = ""
}
});
The line quoted below works when there is no Loop and Merge.
var input = $("QR~"+currentQuestionID);
The problem: I then tried to combine $("QR~"+currentQuestionID)
with Loop and Merge row id (e.g., 1, 2, 3, 4, 5), such as $("1~QR~"+currentQuestionID)
, $("QR~1~"+currentQuestionID)
and $("QR~"+currentQuestionID + "~1")
. Unfortunately, none of them works.
Thank you in advance!
The structure you're looking for is this:
var input = $("QR~${lm://CurrentLoopNumber}_"+currentQuestionID);
i.e. the loop number goes after QR~ and there is an extra _ underscore before the questionID.
I've only been able to test this in an "SE" survey engine, but in another survey that is using the JFE survey engine, the element IDs seem to be structured the same way, so it should work whichever engine your survey is using.