- Posts: 1
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Dropdownlist as a subquestion depending on first dropdown question
- hakan
- Topic Author
- Offline
- New Member
Less
More
11 years 8 months ago #85219
by hakan
Dropdownlist as a subquestion depending on first dropdown question was created by hakan
I would like to have two question like dropdown.
The answer of the first one (you will be able to choose among apr. 100 preeschool) will determine the answering options in the second dropdownlist, which will be max 6 options of departments per preeschool - but of course varying depending on which preeschool that have been choosen in first dropdown.
Yout can see the function here which i've made myself in html and java.
www2.sundsvall.se/enkat/Bou2012/barnomsorgsenkat2012.html
How do you solve that in Limesurvey? I've tried to search but have not found a descent solution.
Thanks in advance!
/Håkan
The answer of the first one (you will be able to choose among apr. 100 preeschool) will determine the answering options in the second dropdownlist, which will be max 6 options of departments per preeschool - but of course varying depending on which preeschool that have been choosen in first dropdown.
Yout can see the function here which i've made myself in html and java.
www2.sundsvall.se/enkat/Bou2012/barnomsorgsenkat2012.html
How do you solve that in Limesurvey? I've tried to search but have not found a descent solution.
Thanks in advance!
/Håkan
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11697
- Thank you received: 2753
11 years 8 months ago #85220
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Dropdownlist as a subquestion depending on first dropdown question
You can probably solve this with a custom Javascript, which is probably the best solution when the first dropdown offers many choices.
I solved it once with conditions and different second questions.
In your case that would be probably quite some work.
I solved it once with conditions and different second questions.
In your case that would be probably quite some work.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13697
- Thank you received: 2501
11 years 8 months ago #85276
by DenisChenu
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.
Replied by DenisChenu on topic Dropdownlist as a subquestion depending on first dropdown question
Hello,
You can use some javascript function:
And use it like that in your survey:
wher qID is the question to filter and filterqID the filtering question.
The script is here:
demonstration.sondages.pro/upload/templa...nade/selectfilter.js
The filter is done on the "sub question" code: for example: is the filterqID hare A then the qID show A1,A2,A233 ....
You can see a demo here:
demonstration.sondages.pro/82885/lang-fr (sorry in french)
Denis
You can use some javascript function:
Code:
/* Function to filter a select by another select In the same page var qID : the numer of question to filter var filterqID : the number of question filtering */ 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 = "<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 it like that in your survey:
Code:
<script type="text/javascript" charset="utf-8"> selectFilterByCode(qID,filterqID); </script>
The script is here:
demonstration.sondages.pro/upload/templa...nade/selectfilter.js
The filter is done on the "sub question" code: for example: is the filterqID hare A then the qID show A1,A2,A233 ....
You can see a demo here:
demonstration.sondages.pro/82885/lang-fr (sorry in french)
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 , plugin development .
I don't answer to private message.
The topic has been locked.
- lfortunato
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
11 years 6 months ago #88128
by lfortunato
Replied by lfortunato on topic Dropdownlist as a subquestion depending on first dropdown question
Hello Denis!
Your solution is really good,
I've just tried the demo and it works exactly like I would.
I would like to ask you some questions on that...thank you in advance!
I have one first question with type List (dropdown)
with a Category separator (
and Question Code = FATH
Answer options
Code Description
A Customer1:Healthy Life
B Customer1:Smart Cities
C Customer1:Alternative energy
D Customer2:Microtechnologies
E Customer2:Nanotechnologies
F Customer3:Innovation
The second question with type List (dropdown)
and Question Code = CHILD
Answer options
Code Description
A1 healthy_food
A2 eating_habits
A3 lifestyle
B1 new_cities
B2 ecological_cities
B3 green_areas
C1 solar_panels
C2 new_fuels
D1 microtech
D2 lithography
D3 optical_lithografy
E1 nanotech
F1 inn_forpeople
F2 inn_forenv
The second question (CHILD) has to display different elements in the dropdown,
based on the previous choice, for example
SELECTED (in the first dropdown)
A Customer1:Healthy Life
THEREFORE WILL BE SHOWN (in the second dropdown)
A1 healthy_food
A2 eating_habits
A3 lifestyle
Following this example, I just need 2 questions dropdown type
instead of 7 questions with conditions for hiding/showing each of them.
Is that correct?
Then I have to put selectfilter.js
in the correct directory, for example
/template/citronade
if I'm using the citronade template.
Regarding the function call
<script type="text/javascript" charset="utf-8">
selectFilterByCode(qID,filterqID);
</script>
where do I have to put this?
Perhaps I have to put the call in the first dropdown question,
in the 'Relevance' field?
Many thanks for all your work
Your solution is really good,
I've just tried the demo and it works exactly like I would.
I would like to ask you some questions on that...thank you in advance!
I have one first question with type List (dropdown)
with a Category separator (
and Question Code = FATH
Answer options
Code Description
A Customer1:Healthy Life
B Customer1:Smart Cities
C Customer1:Alternative energy
D Customer2:Microtechnologies
E Customer2:Nanotechnologies
F Customer3:Innovation
The second question with type List (dropdown)
and Question Code = CHILD
Answer options
Code Description
A1 healthy_food
A2 eating_habits
A3 lifestyle
B1 new_cities
B2 ecological_cities
B3 green_areas
C1 solar_panels
C2 new_fuels
D1 microtech
D2 lithography
D3 optical_lithografy
E1 nanotech
F1 inn_forpeople
F2 inn_forenv
The second question (CHILD) has to display different elements in the dropdown,
based on the previous choice, for example
SELECTED (in the first dropdown)
A Customer1:Healthy Life
THEREFORE WILL BE SHOWN (in the second dropdown)
A1 healthy_food
A2 eating_habits
A3 lifestyle
Following this example, I just need 2 questions dropdown type
instead of 7 questions with conditions for hiding/showing each of them.
Is that correct?
Then I have to put selectfilter.js
in the correct directory, for example
/template/citronade
if I'm using the citronade template.
Regarding the function call
<script type="text/javascript" charset="utf-8">
selectFilterByCode(qID,filterqID);
</script>
where do I have to put this?
Perhaps I have to put the call in the first dropdown question,
in the 'Relevance' field?
Many thanks for all your work
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13697
- Thank you received: 2501
11 years 6 months ago - 11 years 5 months ago #88139
by DenisChenu
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.
Replied by DenisChenu on topic Dropdownlist as a subquestion depending on first dropdown question
You can do something like that in the 2nd questions source (without xssfilter)
If you put the js file in the template, just replace filterqID by the number of the 1st question.
Code:
<script type='text/javascript' src='{TEMPLATEURL}selectfilter.js'></script> <script type="text/javascript" charset="utf-8"> selectFilterByCode({QID},filterqID); </script>
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.
Last edit: 11 years 5 months ago by DenisChenu.
The topic has been locked.
- lfortunato
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
11 years 5 months ago #88596
by lfortunato
Replied by lfortunato on topic Dropdownlist as a subquestion depending on first dropdown question
Dear Denis, after many trials still doesn't work
Attached you'll find my survey example with only the two questions, one dropdown 'father' question
and one dropdown 'children' question.
I've also attached the file selectfilter.js (the same you posted) , which I've put into the server directory
/templates/bluegrey
because I'm using this kind of template for the survey.
If you have any suggestion... really many thanks to you
selectfilter.js
Attached you'll find my survey example with only the two questions, one dropdown 'father' question
and one dropdown 'children' question.
I've also attached the file selectfilter.js (the same you posted) , which I've put into the server directory
/templates/bluegrey
because I'm using this kind of template for the survey.
If you have any suggestion... really many thanks to you
selectfilter.js
Attachments:
The topic has been locked.
- lfortunato
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
11 years 5 months ago #88597
by lfortunato
Replied by lfortunato on topic Dropdownlist as a subquestion depending on first dropdown question
...here is the second file attached
selectfilter.js
selectfilter.js
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13697
- Thank you received: 2501
11 years 5 months ago - 11 years 5 months ago #88604
by DenisChenu
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.
Replied by DenisChenu on topic Dropdownlist as a subquestion depending on first dropdown question
Hello,
I made an error for the inclusion ,
and not
Can i have a link for the survey ? It's impossible to see why it's not work without testing.
Denis
I made an error for the inclusion ,
Code:
<script type='text/javascript' src='{TEMPLATEURL}selectfilter.js'></script>
Code:
<script type='text/javascript' src='{TEMPLATEURL}jqury-ui.js'></script>
Can i have a link for the survey ? It's impossible to see why it's not work without testing.
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 , plugin development .
I don't answer to private message.
Last edit: 11 years 5 months ago by DenisChenu.
The following user(s) said Thank You: lfortunato
The topic has been locked.
- lfortunato
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
11 years 5 months ago #88647
by lfortunato
Replied by lfortunato on topic Dropdownlist as a subquestion depending on first dropdown question
At last, it works!
I want to thank very much Denis for his helpfulness and kindness.
Now It works also with the category separator, and this is exactly what I needed to do!
Good job to all the Limesurvey team!!!
I want to thank very much Denis for his helpfulness and kindness.
Now It works also with the category separator, and this is exactly what I needed to do!
Good job to all the Limesurvey team!!!
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13697
- Thank you received: 2501
11 years 5 months ago #88665
by DenisChenu
If you have some times to put this workaround on our documentation, it can be great :
docs.limesurvey.org/tiki-index.php?page=...ime+using+Javascript
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 , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Dropdownlist as a subquestion depending on first dropdown question
Great news !lfortunato wrote: At last, it works! .... It works also with the category separator,
If you have some times to put this workaround on our documentation, it can be great :
docs.limesurvey.org/tiki-index.php?page=...ime+using+Javascript
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 , plugin development .
I don't answer to private message.
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
11 years 5 months ago #88943
by Mazi
If our hints have been helpful and you enjoy limesurvey please consider a donation to give Limesurvey a future .
We do all this in our free time and you don't have to pay a penny for this software.
Without your help we can't keep this project alive.
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic Dropdownlist as a subquestion depending on first dropdown question
You're welcomelfortunato wrote: At last, it works!
I want to thank very much Denis for his helpfulness and kindness.
Now It works also with the category separator, and this is exactly what I needed to do!
Good job to all the Limesurvey team!!!
If our hints have been helpful and you enjoy limesurvey please consider a donation to give Limesurvey a future .
We do all this in our free time and you don't have to pay a penny for this software.
Without your help we can't keep this project alive.
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.
- lfortunato
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
11 years 5 months ago #88961
by lfortunato
Replied by lfortunato on topic Dropdownlist as a subquestion depending on first dropdown question
You are right, Mazi...
I have already said to my boss that a donation would be important for LS team and certainly for us, as users...
Many thanks to all you
I have already said to my boss that a donation would be important for LS team and certainly for us, as users...
Many thanks to all you
The topic has been locked.