Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Loop through EM variables

  • rhg
  • rhg's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
5 years 9 months ago #170311 by rhg
Loop through EM variables was created by rhg
I have a multiple response question with the qcode "Q1". The subquestions are coded "SQ001", "SQ002", etc. I want to loop through responses in a later question (let's call it "Q2") based on the responses selected in "Q1".

Currently, I have to write a couple lines of code for each subquestion within my loop, like this:
Code:
 for(var i =1;i<=9;i++){
        $("#javatbd{SGQ}" + i).hide();
        if('{Q1_SQ001.NAOK}' == 'Y' ) {
           $("#javatbd{SGQ}" + 1).show();
        }
        if('{Q1_SQ002.NAOK}' == 'Y' ) {
           $("#javatbd{SGQ}" + 2).show();
        }
        if('{Q1_SQ003.NAOK}' == 'Y' ) {
           $("#javatbd{SGQ}" + 3).show();
        }
        if('{Q1_SQ004.NAOK}' == 'Y' ) {
           $("#javatbd{SGQ}" + 4).show();
        }
        if('{Q1_SQ005.NAOK}' == 'Y' ) {
           $("#javatbd{SGQ}" + 5).show();
        }
        if('{Q1_SQ006.NAOK}' == 'Y' ) {
           $("#javatbd{SGQ}" + 6).show();
        }
        if('{Q1_SQ007.NAOK}' == 'Y' ) {
           $("#javatbd{SGQ}" + 7).show();
        }
        if('{Q1_SQ008.NAOK}' == 'Y' ) {
           $("#javatbd{SGQ}" + 8).show();
        }
       if('{Q1_SQ009.NAOK}' == 'Y' ) {
           $("#javatbd{SGQ}" + 9).show();
        }
 
 
  }
 

I'd like to replace '{Q1_SQ001.NAOK}' with something like '{Q1_SQ00' + i + '.NAOK}' but it doesn't work. Is there a way to do this where I don't have to repeat my code for each subquestion?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago #170317 by tpartner
Replied by tpartner on topic Loop through EM variables
Why are you doing this with Javascript instead of with sub-question relevance?

(I also don't understand why you have 9 IF statements in every iteration of the loop)

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • rhg
  • rhg's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
5 years 9 months ago #170367 by rhg
Replied by rhg on topic Loop through EM variables
There is no sub-question relevance option for radio button, it is available for checkbox. I have 9 if statement so that I can replace VAR in {Q1_SQ00<VAR>.NAOK} by number
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago #170376 by tpartner
Replied by tpartner on topic Loop through EM variables
If it's a list-radio, you can use array filter - manual.limesurvey.org/Question_type_-_Li...r_.28array_filter.29

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: rhg
The topic has been locked.
  • rhg
  • rhg's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
5 years 9 months ago #170379 by rhg
Replied by rhg on topic Loop through EM variables
I am not sure I understand. See below example:

Which are your favorite cities? (checkbox question)
a. London
b. NY (selected)
c. LA
d. Miami (selected)

Say, the next question is which is your most favorite? (radio button) (it should show the options selected in above question)
a. NY
b. Miami

I have used JS to solve this but I am not sure how I should use array filter to use it.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 9 months ago #170382 by DenisChenu
Replied by DenisChenu on topic Loop through EM variables
Did you look at the manual ? Put the code of checkbox question in the array filter of the radio list.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: rhg
The topic has been locked.
  • rhg
  • rhg's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
5 years 8 months ago #171697 by rhg
Replied by rhg on topic Loop through EM variables
Got it thank you so much.. it was so easy
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose