Willkommen, Gast Benutzername: Passwort: Angemeldet bleiben:

## Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how 2 Jahre 6 Monate her #87285

 docl OFFLINE Fresh Lemon Beiträge: 8 Karma: 0 I have two questions of drop down list type. The answers for the second question depend on question one. So far I have solved this by creating the first question and then for each answer to the first question I have created another question that is only shown (using relavance equation)if the corresponding answer in q1 is chosen. It works but creates a small challenge - being that Q2 is no longer just one question but multiple questions - which I have to correct manually afterwards when doing statistics since it should actually only be one question.. Actually in the end Q1 and Q2 could be just one common question, but the answer list would be very long and to make it easier to choose the correct answer Q2 is made as a subgroup of Q1.. An example of what I'm trying to accomplish: "Overall question" Where are you from? (this could be a very long list of countries, so to make it easier for the user I would divide it in two questions) Q1 then being Continent? -- Asia Africa Europe etc.. -- Q2 should then be another dropdown list with countries dependent on the answer to Q1, but preferably still just one question.. Country? --- if Q1=Asia; China if Q1=Asia; Thailand etc if Q1=Europe; Denmark if Q1=Europe; Germany etc my solution now is that Q2 is actually Q2,Q3,Q4 etc Q2 if Q1=Asia Q3 if Q1=Europe etc. Any ideas how to keep it as just two questions (mostly for statistical reasons)? Letzte Änderung: 2 Jahre 6 Monate her von docl. Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Re: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how 2 Jahre 6 Monate her #87291

 DenisChenu OFFLINE Moderator Lime Beiträge: 7079 Dank erhalten: 957 Karma: 282 There are a lot of solution. I have already this one: Add this in template.js:```/* Function to filter a select by another select In the same page var qID : the number of question to filter var filterqID : the number of question filtering Copyleft 2012 Denis Chenu licence GPL v3 */ function selectFilterByCode(qID,filterqID){ \$(document).ready(function(){ var idSelectFilter = \$("#question"+qID).find("select").attr('id'); \$("#"+idSelectFilter).hide(); var idSelectFiltering = \$("#question"+filterqID).find("select").attr('id'); if(typeof idSelectFilter === 'undefined' || typeof idSelectFiltering === 'undefined' ) { return false; } else { var idNewSelectFilter = 'select'+qID var NewSelectElement = ""; \$("#"+idSelectFilter).after(NewSelectElement); \$("#"+idNewSelectFilter).width(\$("#"+idSelectFilter).width()); \$("#"+idSelectFiltering).change(function(){ \$('#'+idSelectFilter).val(''); \$('#'+idNewSelectFilter).val(''); var valuefilter=\$(this).val(); \$('#'+idNewSelectFilter+' option').not(':first').remove(); \$('#'+idSelectFilter+' option').each(function(){ if(\$(this).attr('value').indexOf(valuefilter)==0){ \$(this).clone().appendTo('#'+idNewSelectFilter); } }); });   \$("#"+idNewSelectFilter).change(function(){ \$('#'+idSelectFilter).val(\$(this).val()); });   if(\$("#"+idSelectFiltering).val()!=''){ var valuefilter=\$("#"+idSelectFiltering).val(); \$('#'+idSelectFilter+' option').each(function(){ if(\$(this).attr('value').indexOf(valuefilter)==0){ \$(this).clone().appendTo('#'+idNewSelectFilter); } }); if(\$("#"+idSelectFilter).val()!=''){ \$('#'+idNewSelectFilter).val(\$("#"+idSelectFilter).val()); } } } }); }``` And use 2 question: the second question have string code starting like the first one. In the second question, lauch the script:`````` Put a survey sample example and a complete js file Demo: demonstration.sondages.pro/index.php?sid...85&newtest=Y&lang=fr Denis PS: can't upload js file : find it here: demonstration.sondages.pro/upload/templa...nade/selectfilter.js Anhang: limesurvey...2885.lss (60KB) Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?). A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous Official LimeSurvey Partner | Web development | SkeletonQuest, RWD for LimeSurvey Letzte Änderung: 2 Jahre 6 Monate her von DenisChenu. Der Administrator hat öffentliche Schreibrechte deaktiviert. Folgende Benutzer bedankten sich: docl, mfpereira

## Re: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how 2 Jahre 6 Monate her #87335

 docl OFFLINE Fresh Lemon Beiträge: 8 Karma: 0 Perfect, works like a charm Thanks Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Re: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how 2 Jahre 3 Monate her #91572

 dweisser OFFLINE Gold Lime Beiträge: 205 Dank erhalten: 5 Karma: 5 Looks like a simple solution, but I can;t get it to work. I added the code to the template.js in "Copy of default" template. And followed instructions to the letter. The thing is that this is not the only - current -JavaScript problem I'm having. I have enabled the survey (all surveys) to read javascript by going to Global Settings->Security->Filter HTML for XSS and setting it to "No". I tested that javascript is enabled by using the following in a third question: And I get the alert. What am doing wrong here? Any thoughts or suggestions would be much appreciated. In fact, I downloaded the sample survey you most graciously provided and it doesn't work for me either. Thank you as always, David Letzte Änderung: 2 Jahre 3 Monate her von dweisser. Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Re: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how 2 Jahre 3 Monate her #91594

 dweisser OFFLINE Gold Lime Beiträge: 205 Dank erhalten: 5 Karma: 5 And seven hours later.... I think I found the solution. Even though I updated the template.js I'm using for the survey with the function as defined in the previous posts, it was not *making it's way* to the survey. When I pasted that function in its entirety along with the function call in the source of the Filtered question, that did the trick. If anyone has thoughts on why the template.js did not adequately communicate the function to the survey questions, I'd sure be interested. Thanks wonderful Limers! David Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Re: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how 2 Jahre 1 Monat her #94517

 mfpereira OFFLINE Fresh Lemon Beiträge: 7 Karma: 0 Hi good morning. I'm trying use your instructions to make se same question you use in the demo. But I get a error. I can´t download de file you post. Can you send me the file .lss please? Thanks Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Re: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how 2 Jahre 1 Monat her #94518

 DenisChenu OFFLINE Moderator Lime Beiträge: 7079 Dank erhalten: 957 Karma: 282 You have only to click on: www.limesurvey.org/media/kunena/attachme...vey_survey_82885.lss ??? Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?). A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous Official LimeSurvey Partner | Web development | SkeletonQuest, RWD for LimeSurvey Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Re: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how 2 Jahre 1 Monat her #94521

 mfpereira OFFLINE Fresh Lemon Beiträge: 7 Karma: 0 Sorry the ignorance. But when I click the link a new web page is open with a code. How a put this in .lss format to import for limesurvey. Thanks again Der Administrator hat öffentliche Schreibrechte deaktiviert.

## Re: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how 2 Jahre 1 Monat her #94522

 DenisChenu OFFLINE Moderator Lime Beiträge: 7079 Dank erhalten: 957 Karma: 282 Right click / save as or when the page is open : save. Denis Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?). A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous Official LimeSurvey Partner | Web development | SkeletonQuest, RWD for LimeSurvey Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd