Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Can I combine List(radio) and List (dropdown) into one question?

More
4 years 6 months ago #225503 by xueting
Please help us help you and fill where relevant:Your LimeSurvey version: [3.28.0]Own server or LimeSurvey hosting: TU/eSurvey theme/template: Can I combine List(radio) and List (dropdown) into one question?==================

Hi all,

In the following situation, if 'others' in the List(radio) question is selected, then the next List (dropdown) question would show.
 

But I suppose seems a more efficient way is to insert dropdown into the 'others' option of List(radio) like the following photoshopped picture shows.
 

I was wondering is it possible? Thank you for your attention.

Regards,
Xueting
 

Please Log in to join the conversation.

More
4 years 6 months ago #225514 by tpartner
You can use JavaScript to move the drop-down from the following question into the last option of the list-radio.

Something like this in the source of the list-radio:

Code:
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // The text for the "Please choose" option var chooseText = { 'en': 'Please choose...', 'de': 'Bitte auswählen...', 'fr': ' Veuillez choisir ...' } // Identify this question var qID = '{QID}'; var thisQuestion = $('#question'+qID); var nextQuestion = $(thisQuestion).nextAll('.list-dropdown:eq(0)'); var lang = $('html').attr('lang'); // Hide the next question nextQuestion.hide(); // Move the dropdown $('.answer-item.radio-item:last', thisQuestion).append($('.answer-item', nextQuestion)); // Cleanup styles $('.answer-item.radio-item .answer-item', thisQuestion).css({ 'display': 'inline-block', 'margin-left': '1em', 'padding': '0' }); function handleOther() { if($('.answer-item.radio-item:last :radio:checked', thisQuestion).length == 0) { $('.answer-item.radio-item .answer-item', thisQuestion).hide(); $('.answer-item.radio-item .answer-item input[type="hidden"]', thisQuestion).val(''); $('.answer-item.radio-item .answer-item select', thisQuestion).val('').trigger('change'); } else { $('.answer-item.radio-item .answer-item', thisQuestion).show(); } } // Initial state handleOther(); var iChooseText = chooseText['en']; if(lang in chooseText) { iChooseText = chooseText[lang]; } if($('select.form-control option[value=""]', thisQuestion).length == 0) { $('select.form-control', thisQuestion).prepend('<option value="">'+iChooseText+'</option>'); } // Listener on the radios $('.answer-item.radio-item :radio', thisQuestion).on('click', function(e) { handleOther(); }); }); </script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...4594.lss
File Size:38.27 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: xueting

Please Log in to join the conversation.

More
4 years 6 months ago #225636 by xueting
Thank you Tony Partner for your solution. It's amazing to see the idea come true!

Regards,
Xueting

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose