I'd like to use Javascript to set up the display logic for individual rows in a single-choice matrix table question in Qualtrics. I've always done this in the past with the usual click-through method, but I often have 100+ rows to do this for, and it'd save a ton of time to be able to do this programmatically.
I've tried inserting the following into "Add JavaScript" for the question I'm trying to add the display logic to:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Set display logic*/
if ('${q://QID2/SelectedAnswerRecode/1}' < 3) {'${q://QID3/ChoiceDescription/1}'.style.visibility='hidden';}
if ('${q://QID2/SelectedAnswerRecode/2}' < 3) {'${q://QID3/ChoiceDescription/2}'.style.visibility='hidden';}
});
The idea is that an answer with a value of at least 3 in row 1 of QID2 (also a single-choice matrix table) is required for row 1 of matrix table QID3 to appear, and so on. As it is, is appears unresponsive - rows in QID3 are still displayed even if selected values in the corresponding rows of QID2 are < 3.
I've also tried style.display='none'
instead of style.visibility='hidden'
with no success. My experience with Javascript is limited, so I suspect it's some kind of syntax issue.
The problem is indeed with your syntax. You need to hide an html element and '${q://QID3/ChoiceDescription/1}' is not an html element (it is the innerHTML of a label). Even if it were an html element, the syntax is wrong (it wouldn't be in quotes).
It is best to use prototypejs when possible, so if the element were named 'element' the command would be:
To find the correct elements to hide, you need to identify and find them by element id or some combination of element tag, class and attribute. It could be done using choice description, but it would take a lot more code and wouldn't be very efficient.