Can I use JavaScript instead of Display logic | XM Community
Solved

Can I use JavaScript instead of Display logic

  • 15 February 2019
  • 5 replies
  • 202 views

Userlevel 4
Badge +16
  • QPN Level 3 ●●●
  • 162 replies
Dear Community,

I've to handle a list with 190 items. This is used in different questions where only specific items are shown.

Of course the task can be done by using the display function. However this is a bit of a Sysophos' task and it is rather error prone.

All questions and solutions I've found in this forum so far still rely on the display logic. In order to avoid using the display logic feature I'd rather would use only some JavaScript and embedded data.

Basically I would set embedded data arrays like on displayed and not selected answer options and selected items.
The idea would be to refer to the embedded in a JavaScript function which shows only the required list items.

Has anybody an idea how this can be accomplished?

Thanks for your support

Rudi
icon

Best answer by TomG 15 February 2019, 16:01

View original

5 replies

Userlevel 7
Badge +27
Have you considered using Carry Forward instead? You can use display logic and/or Advanced Randomization on just a few questions then Carry Forward the choices to other questions.
Userlevel 4
Badge +16
Hi Tom,
thanks for your fast reply.
yes I have tried this out.

However the task is a bit different.
Q1: shows all items
Q2: shows all items displayed in Q1 but not selected in Q1
Q3 : shows all items selected in Q1 and max 3 items selected in Q2

Hence, the idea was to have a function which creates the set of items to be shown in Q3 by script, else I would need to create at least 180 embedded data variables which then have to be added to the display logic for each answer stub.

I hope this makes it a bit clearer,

Best regards

Rudi
Userlevel 7
Badge +27
> @Rudi said:
> However the task is a bit different.
> Q1: shows all items
> Q2: shows all items displayed in Q1 but not selected in Q1
> Q3 : shows all items selected in Q1 and max 3 items selected in Q2
>
> Hence, the idea was to have a function which creates the set of items to be shown in Q3 by script, else I would need to create at least 180 embedded data variables which then have to be added to the display logic for each answer stub.
You wouldn't have to add 180 embedded variables, but you would have to add display logic to 180 choices.

To do this by JavaScript, carry forward all 180 choices from Q1 into Q3, then:
1. Hide all the choices
2. Split the piped selected choices from Q1 into an array
3. Loop through the array and unhide the corresponding choices
4. Split the piped selected choices from Q2 into an array
5. Shuffle the array
6. Splice the array to 3 items
7. Loop through the array and unhide the corresponding choices
Userlevel 4
Badge +16
Hi Tom, sorry for thanking you for your detailled answer late. It's very helpful and is exactly what I have been trying. The only remaining question is how do I hide and unhide answer choices in qualtrics. Do we have a function for this?
Best regards

Rudi
Userlevel 7
Badge +27
> @Rudi said:
> Hi Tom, sorry for thanking you for your detailled answer late. It's very helpful and is exactly what I have been trying. The only remaining question is how do I hide and unhide answer choices in qualtrics. Do we have a function for this?
> Best regards
>
> Rudi
>

Select the `<li>` element containing the applicable input checkbox and use the jQuery hide() and show() functions.

Leave a Reply