# Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how

5 Jahre 2 Monate her - 5 Jahre 2 Monate her #87285 von docl
docl erstellte das Thema Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how
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: 5 Jahre 2 Monate her von docl.

Bitte Anmelden um an der Konversation teilzunehmen.

5 Jahre 2 Monate her - 5 Jahre 2 Monate her #87291 von DenisChenu
DenisChenu antwortete auf das Thema: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how
There are a lot of solution.

```/* 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){
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 = "<select id='"+idNewSelectFilter+"'><option value=''>"+\$("#"+idSelectFilter+" option[value='']:first").text()+"</option></select>";
\$("#"+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:
```<script type="text/javascript" charset="utf-8">
selectFilterByCode({QID},{FILTERQUEST});
</script>```

Put a survey sample example and a complete js file
Demo: demonstration.sondages.pro/index.php?sid...85&newtest=Y&lang=fr
Denis

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 .
##### Anhang:
Letzte Änderung: 5 Jahre 2 Monate her von DenisChenu.
Folgende Benutzer bedankten sich: docl, mfpereira

Bitte Anmelden um an der Konversation teilzunehmen.

5 Jahre 2 Monate her #87335 von docl
docl antwortete auf das Thema: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how
Perfect, works like a charm
Thanks

Bitte Anmelden um an der Konversation teilzunehmen.

4 Jahre 11 Monate her - 4 Jahre 11 Monate her #91572 von dweisser
dweisser antwortete auf das Thema: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how
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:
<script type="text/javascript" charset="utf-8">
});
</script>

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: 4 Jahre 11 Monate her von dweisser.

Bitte Anmelden um an der Konversation teilzunehmen.

4 Jahre 11 Monate her #91594 von dweisser
dweisser antwortete auf das Thema: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how
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

Bitte Anmelden um an der Konversation teilzunehmen.

4 Jahre 9 Monate her #94517 von mfpereira
mfpereira antwortete auf das Thema: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how
Hi good morning.

I'm trying use your instructions to make se same question you use in the Demo.

But I get a error.

Can you send me the file .lss please?

Thanks

Bitte Anmelden um an der Konversation teilzunehmen.

4 Jahre 9 Monate her #94518 von DenisChenu
DenisChenu antwortete auf das Thema: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how

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 .

Bitte Anmelden um an der Konversation teilzunehmen.

4 Jahre 9 Monate her #94521 von mfpereira
mfpereira antwortete auf das Thema: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how
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

Bitte Anmelden um an der Konversation teilzunehmen.

4 Jahre 9 Monate her #94522 von DenisChenu
DenisChenu antwortete auf das Thema: Two questions - both dropdown lists, answer list to Q2 depends on Q1 - how
Right click / save as or when the page is open : save.

Denis

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 .

Bitte Anmelden um an der Konversation teilzunehmen.