- Posts: 117
- Thank you received: 9
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Change options shown in a Language Switch type question
- paulfiner
- Topic Author
- Offline
- Premium Member
Less
More
3 months 3 weeks ago #254039
by paulfiner
Change options shown in a Language Switch type question was created by paulfiner
Please help us help you and fill where relevant:
Your LimeSurvey version: 3.25.17
Own server or LimeSurvey hosting: Own
Survey theme/template:
==================
I have a survey that is translated into 9 languages with English as the base language.
For one of my countries, which is passed in via the url, I would like to present a language change option on the first page but I only want to show the 3 possible languages for the country, not all 9 options.
Can I hide the options that are not relevant using javascript?
Thanks.
Your LimeSurvey version: 3.25.17
Own server or LimeSurvey hosting: Own
Survey theme/template:
==================
I have a survey that is translated into 9 languages with English as the base language.
For one of my countries, which is passed in via the url, I would like to present a language change option on the first page but I only want to show the 3 possible languages for the country, not all 9 options.
Can I hide the options that are not relevant using javascript?
Thanks.
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
3 months 3 weeks ago #254043
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Change options shown in a Language Switch type question
Can you attach a sample survey containing the relevant question(s)?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.
- paulfiner
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 117
- Thank you received: 9
3 months 3 weeks ago #254048
by paulfiner
Replied by paulfiner on topic Change options shown in a Language Switch type question
Hi Tony,
Attached is a small lss file where the language change question is shown if the country is Italy.
I would like to only show English and Italian in the language change options if possible.
Many thanks,
Paul
Attached is a small lss file where the language change question is shown if the country is Italy.
I would like to only show English and Italian in the language change options if possible.
Many thanks,
Paul
Attachments:
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
3 months 3 weeks ago #254060
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Change options shown in a Language Switch type question
This script will remove all languages except English and Italian if the previous country question equals 4.
Sample survey attached:
Code:
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // The language codes to keep in the dropdown var relevantLangs = ['en', 'it']; // Identify this question var thisQuestion = $('#question{QID}'); // Only do this if the previous country question == 4 if('{CT}' == '4') { // Loop through the dropdown options $('select.languagesurvey option', thisQuestion).each(function(i) { // Remove unwanted languages if(!relevantLangs.includes($(this).val())) { $(this).remove(); } }); } }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.
- paulfiner
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 117
- Thank you received: 9
3 months 3 weeks ago #254064
by paulfiner
Replied by paulfiner on topic Change options shown in a Language Switch type question
That's great, thanks Tony.
Is it possible to change the wording on the labels for the pop-up?
My client doesn't want the word 'informal' showing so it would just show Italiano instead of Italiano (informel).
Is it possible to change the wording on the labels for the pop-up?
My client doesn't want the word 'informal' showing so it would just show Italiano instead of Italiano (informel).
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
3 months 3 weeks ago #254068
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Change options shown in a Language Switch type question
What pop-up? Do you mean the language-select dropdown?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.
- paulfiner
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 117
- Thank you received: 9
3 months 3 weeks ago #254069
by paulfiner
Replied by paulfiner on topic Change options shown in a Language Switch type question
Yeah, sorry I meant dropdown menu. I need to be able to change the text for some the entries.
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
3 months 3 weeks ago #254070
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Change options shown in a Language Switch type question
This will modify the dropdown labels:
So, you can combine it with the first script like this:
Sample survey attached:
Code:
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // The new language-select labels var langLabels = { 'de-informal': 'Deutsch', 'it-informal': 'Italiano' } // Identify this question var thisQuestion = $('#question{QID}'); // Modify the language-select labels $.each(langLabels, function(key, value) { $('select.languagesurvey option[value="'+key+'"]', thisQuestion).text(value); }); }); </script>
So, you can combine it with the first script like this:
Code:
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // The language codes to keep in the dropdown var relevantLangs = ['en', 'it']; // The new language-select labels var langLabels = { 'de-informal': 'Deutsch', 'it-informal': 'Italiano' } // Identify this question var thisQuestion = $('#question{QID}'); // Modify the language-select labels $.each(langLabels, function(key, value) { $('select.languagesurvey option[value="'+key+'"]', thisQuestion).text(value); }); // Only do this if the previous country question == 4 if('{CT}' == '4') { // Loop through the dropdown options $('select.languagesurvey option', thisQuestion).each(function(i) { // Remove unwanted languages if(!relevantLangs.includes($(this).val())) { $(this).remove(); } }); } }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.
- paulfiner
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 117
- Thank you received: 9
3 months 3 weeks ago #254072
by paulfiner
Replied by paulfiner on topic Change options shown in a Language Switch type question
Genius!!
Many thanks Tony. I've got a survey being done in 20 languages next week so this will help massively.
Cheers,
Paul
Many thanks Tony. I've got a survey being done in 20 languages next week so this will help massively.
Cheers,
Paul
Please Log in to join the conversation.