While this issue has been addressed a few times here and here, subsequent Qualtrics updates have made it difficult to continue to apply these solutions.
My objective: count up the number of text boxes containing responses from 2 questions and use that number to determine what gets displayed in a third. The following javascript code used in a text question type on a page separating the second and third questions works fine:
Qualtrics.SurveyEngine.addOnload(function()
{
//Count up the number of text boxes with anything in them
var count = 0;
if('${q://QID1/ChoiceTextEntryValue/1}') count++;
if('${q://QID1/ChoiceTextEntryValue/2}') count++;
//etc...
if('${q://QID2/ChoiceTextEntryValue/1}') count++;
if('${q://QID2/ChoiceTextEntryValue/2}') count++;
//etc...
//Set count as embedded data (added to survey flow earlier)
Qualtrics.SurveyEngine.setEmbeddedData('count', count);
};
The problem is that I have a useless page between my second and third questions. If I use display logic to hide my intervening question with this code, the code doesn't execute. If I use javascript to hide the question and automatically move to the next page as described here, it works, but then the user can't move back in the survey because jQuery('#NextButton').click();
returns them to the third question. I've tried wrapping the above code in a substitute NextButton
code and moving it to the same page with QID2 as shown here with at least one update that I could figure out:
this.hideNextButton ();
$('NextButton').insert({
before: "<input id=\"checkButton\" type=\"button\" value=\" -> \" title=\" -> \">"
});
$('checkButton').onclick = function() {
//Previous count and set code here
$('NextButton').click();
};
This works for counting up everything from QID1 (located on the previous page), but doesn't catch those from QID2 (same page).
I've also tinkered with placing code in addOnReady
and addOnUnload
to no avail.
What I need is either 1) an update to the solution that hides the question on an intervening page that modifies the Back button on the page with my third question to kick the participant two pages back, or 2) an update to the substitute button solution that will grab counts from the question on the same page.