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
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 months 3 weeks ago #254039 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.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 3 weeks ago #254043 by tpartner
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
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 months 3 weeks ago #254048 by paulfiner
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

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 3 weeks ago #254060 by tpartner
This script will remove all languages except English and Italian if the previous country question equals 4.

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: 

File Attachment:

File Name: limesurvey...5571.lss
File Size:49 KB

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
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 months 3 weeks ago #254064 by paulfiner
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).

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 3 weeks ago #254068 by tpartner
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
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 months 3 weeks ago #254069 by paulfiner
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
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 3 weeks ago #254070 by tpartner
This will modify the dropdown labels:

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: 

File Attachment:

File Name: limesurvey...5572.lss
File Size:52 KB

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
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 months 3 weeks ago #254072 by paulfiner
Genius!!

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.

Lime-years ahead

Online-surveys for every purse and purpose