Change the language at any question
To change the survey language at anytime in your questionnaire follow this step by step process:
1. Create a ^Language^ question
2. Add routings 'Set language'
- for each language (in our example 3)
- after '{All Questions}'
- and execute the routing 'during' and 'after' each question.
3. Add script
In Design's Internet Settings, select the Contents tab and add in "Before content"
and copy and paste in . . .
"After Content"
<input type="submit" value="<>" style="visibility:hidden" name="askiaStay" />
"Before content"
<input type ="hidden" id="_Language" name ="_Language" value=""> <select style="float:right;" onchange="getComboValue(this)"> <option id="L1" value="!!^Language^.Responses[1].inputValue().ToNumber()!!">English</option> <option id="L2" value="!!^Language^.Responses[2].inputValue().ToNumber()!!">Français</option>
<option id="L3" value="!!^Language^.Responses[3].inputValue().ToNumber()!!">Italiano</option>
</select> <script> function selectOption() { document.getElementById("L!!^Language^.value!!").selected=true; } function getComboValue(sel) { var value = sel.options[sel.selectedIndex].value; document.getElementById("_Language").value = value; document.getElementsByName("askiaStay")[0].click(); } selectOption(); </script>
Modify the code
You will need to change the reference of your Language question in the code so it is named differently, and replace Language with the shortcut caption of your language variable.
You will also need to modify a couple of other items:
- The list of options should be the same as your list in the definition of your Language variable.
- The id and value should be equal to the order of your items in the definition for the id and for the internal response code value. So if you have English, Français and Italiano, English you will need to have an id of L1, Français of L2 and so on. And the value !!^Language^.Responses[1].inputValue().ToNumber()!! for English, !!^Language^.Responses[2].inputValue().ToNumber()!! for Français and so on.
This piece of code will add a drop down menu on all the screens with the list of languages available and when you will select another language, the system will update the screen with the relevant language selected.
Finally, if you show the Language question, ensure you hide the drop down menu of the languages. To be able to do this, go to the properties of the Language screen and in the Contents tab, untick use default for the Before content and make it blank.
Explanation of the code
The first row create a hidden input which will be used to modify the value of a previous question (here the Language variable). The name's parameter should start with an underscore and then the shortcut of the variable. Please note that it doesn't work for variables inside a loop.
<input type="hidden" id="_Language" name="_Language" value="">
Then we use JavaScript to populate the input hidden with the selected language and click on the askiaStay element which is generated automatically on all pages of an Askia survey. The askiaStay element is an input image so the effect is the data stored in the input hidden is sent to the variable and the page is refreshed with the new language. Note that when we use the input hidden with the _shortcut name to modify the data of a previous question, the system reads and executes the routing attached to this previous question.