Loop through EM variables

More
1 month 3 weeks ago #170311 by rhg
rhg created the topic: Loop through EM variables
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:
 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?

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #170317 by tpartner
tpartner replied the 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.

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #170367 by rhg
rhg replied the 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

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #170376 by tpartner
tpartner replied the 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

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #170379 by rhg
rhg replied the 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.

Please Log in or Create an account to join the conversation.

More
1 month 3 weeks ago #170382 by DenisChenu
DenisChenu replied the 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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
The following user(s) said Thank You: rhg

Please Log in or Create an account to join the conversation.

More
3 weeks 2 days ago #171697 by rhg
rhg replied the topic: Loop through EM variables
Got it thank you so much.. it was so easy

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!