For various reasons I would like to let my respondents select their language with a question instead of the language drop down selector. I found the code to do this over here: https://gist.github.com/marketinview/48187d5251ac0fedf555cbd0f2ac7c7a. It works perfectly when I add a list question. However, I would like to know how I can change this code so that it works with a dropdown question? I’ve tried a couple of things myself but I’m unable to hide the langCodes if I change the question from a list to a dropdown.
Solved
Select language with dropdown question instead of language drop down selector

Best answer by Tom_1842
So I don’t think you can use <span> inside of a select element's <option>, which is how the Multiple Choice dropdown is laid out. So you will see EnglishEN, FrenchFR, etc. Instead, you can include the language without the language code, and use JS to set the language code based on the selected language. Try creating a Multiple Choice question and set its Format to Dropdown, add the choices "English" and "French" and then add the below to the question's JavaScript in the OnReady section:
jQuery("#"+this.questionId+" select").on('input', function() {
var selectedOption = jQuery(this).find("option:selected").text();
if (selectedOption == "English"){
var langCode = "EN";
}
if (selectedOption == "French"){
var langCode = "FR";
}
jQuery("#Q_lang").val(langCode).trigger('change');
});
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.