The LimeSurvey Fund-Raiser 2012 is complete. Thank you for donating a total of 25,000 USD!     List of donors »
 Willkommen, Gast Benutzername: Passwort: Angemeldet bleiben:
 Seite:1

## Iterate through questions to filter answers 5 Monate 3 Wochen her #88810

 garf OFFLINE Fresh Lemon Beiträge: 4 Karma: 0 Hi all, I've been playing with LimeSurvey 2 of late and I have to say I'm totally impressed! I've run into a situation though and I'm wondering if anyone can help? To keep it simple: I have 2 ranking type questions(the real survey has 42). I have 4 pools of possible answers for each ranking, say A,B,C,D. Each answer code begins with one of these letters, so, A1, B1, C1, D1 - A2, B2, C2, D2 I only want to score items ranked in 1'st and 2'nd place. Whatever pool letter is Ranked 1 will get 5 points, 2nd place 3 - 4th and 5th are irrelevant. At the end of the survey, I want to summarize scores/totals across the questions pools for A, B, C D . -- -- -- -- Q1 Q2 Rank 1 -- A A Rank 2 -- C B -- -- -- -- --Q1-- -- Q2 Rank 1 -- A=5 -- A=5 Rank 2 -- C=3 -- B=3 = A=10, B=3, C=3, D=0 I tried using something like this to give me some totals if(substr(Q1_1, 0, 1) == "A", ATotal=ATotal + 5, if(substr(Q1_1, 0, 1) == "B", BTotal=BTotal + 5, if(substr(Q1_1, 0, 1) == "C", CTotal=CTotal + 5, if(substr(Q1_1, 0, 1) == "D", DTotal=DTotal + 5, 0)))) if(substr(Q1_2, 0, 1) == "A", ATotal=ATotal + 3, if(substr(Q1_2, 0, 1) == "B", BTotal=BTotal + 3, if(substr(Q1_2, 0, 1) == "C", CTotal=CTotal + 3, if(substr(Q1_2, 0, 1) == "D", DTotal=DTotal + 3, 0)))) ..but I get scores like 39 and 43 etc... So it seems like the code keeps getting triggered when there is activity in the survey. Has anyone seen this before or have some suggestions how to handle this? The problem is when you have 42 answers x 4, the equation gets really long. Is there a way to filter or iterate through the question perhaps with a scripted loop or something? Thanks for any guidance in advance! G Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Re: Iterate through questions to filter answers 5 Monate 3 Wochen her #88826

 DenisChenu OFFLINE Moderator Lime Beiträge: 4374 Dank erhalten: 451 Karma: 165 Just an idea, After each ranking (the number is X, example for first and A), add 4 equation question (attribute : numeric):```CODE : SUMA01 Text : {(if(Q1_1=="A1",5,if(Q1_2=="A1",4,0))} CODE : SUMB01 Text : {(if(Q1_1=="B1",5,if(Q1_2=="B1",4,0))} CODE : SUMC01 Text : {(if(Q1_1=="C1",5,if(Q1_2=="C1",4,0))} CODE : SUMD01 Text : {(if(Q1_1=="D1",5,if(Q1_2=="D1",4,0))}```For the second```CODE : SUMA02 Text : {(if(Q2_1=="A2",5,if(Q2_2=="A2",4,0))} CODE : SUMB02 Text : {(if(Q2_1=="B2",5,if(Q2_2=="B2",4,0))} CODE : SUMC02 Text : {(if(Q1_1=="C2",5,if(Q1_2=="C2",4,0))} CODE : SUMD02 Text : {(if(Q1_1=="D2",5,if(Q1_2=="D2",4,0))}```(each equation are the same, just change X. At the end of the survey: CODE : TOTALA Text : {sum(SUMA01,SUMA02,SUMA03 .... )} It's more easy to do, just a long way, but you already adding 42 ranking question. Denis Bug report | LimeSurvey Version 2.05 beta 1 released! | Please, read the documentation Denis Chenu Libriste convaincu: Official LimeSurvey Partner: Sondages Pro : Vos enquêtes sur internet Web development : Développement de Logiciels Libres pour Internet" Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Re: Iterate through questions to filter answers 5 Monate 3 Wochen her #88906

 garf OFFLINE Fresh Lemon Beiträge: 4 Karma: 0 Thanks Denis for the great idea! I have to admit, I didn't even think to break it down that way. In the interest of expanding my knowledge, would you or someone else here on the forum know, if I did want to run a script after the last question, say something like below; given quesiton code is A1_1. A2_2 ..etc. Is it possible to access the questions this way? ```       ``` Thanks again for your help!! Garf Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Re: Iterate through questions to filter answers 5 Monate 3 Wochen her #88931

 tpartner OFFLINE LimeSurvey Team Beiträge: 2853 Dank erhalten: 423 Karma: 243 It looks to me like the loop should work, but I think the question codes should be Q1_1, Q1_2... Cheers, Tony LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project. Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Re: Iterate through questions to filter answers 5 Monate 3 Wochen her #88970

 DenisChenu OFFLINE Moderator Lime Beiträge: 4374 Dank erhalten: 451 Karma: 165 `str= "{Q" + i + "_1}"`Thinks EM manager don't work here. EM mangaer look at`Q" + i + "`vars, and this var donesn't exist. Denis Bug report | LimeSurvey Version 2.05 beta 1 released! | Please, read the documentation Denis Chenu Libriste convaincu: Official LimeSurvey Partner: Sondages Pro : Vos enquêtes sur internet Web development : Développement de Logiciels Libres pour Internet" Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Re: Iterate through questions to filter answers 5 Monate 3 Wochen her #88972

 DenisChenu OFFLINE Moderator Lime Beiträge: 4374 Dank erhalten: 451 Karma: 165 ```var questionArray=new Array("{Q1_1","Q1_2","Q1_3" ... ); len=questionArray.length; answer = null; for (var i = 0; i < len; i++) { answer = questionArray[i]; switch(answer.substring(0,1)) { case "A": AT=AT+5; break;   case "B": BT=BT+5; break;   case "C": CT=CT+5; break;   case "D": DT=DT+5; break;   } }```Don't look at the number of {/} maybe some error. Denis Bug report | LimeSurvey Version 2.05 beta 1 released! | Please, read the documentation Denis Chenu Libriste convaincu: Official LimeSurvey Partner: Sondages Pro : Vos enquêtes sur internet Web development : Développement de Logiciels Libres pour Internet" Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Re: Iterate through questions to filter answers 5 Monate 3 Wochen her #89010

 garf OFFLINE Fresh Lemon Beiträge: 4 Karma: 0 Thanks Denis! That solved the mystery for me... I was having a problem with version 2 and direct script in the question with {INSERTANS:SQGA}. It kept filling up my script with html etc. The {qcode} works perfectly in script and the array solution makes perfect sense. Thanks again for your help! Garf Der Administrator hat öffentliche Schreibrechte deaktiviert.
 Seite:1
Moderatoren: DenisChenu, ITEd