Welcome to the LimeSurvey Community Forum

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

Combining two types of questions

  • simatz
  • simatz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 3 months ago - 4 years 3 months ago #192231 by simatz
Combining two types of questions was created by simatz
Hello, I'm trying to combine two types of questions in one.
I have a question that answers options are of two types:
radio buttons
OR
radio buttons with text

like in the added picture.

Does anybody have an idea how to do this?

Thanks
S
Attachments:
Last edit: 4 years 3 months ago by simatz.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 3 months ago #192232 by tpartner
Replied by tpartner on topic Combining two types of questions
Two options...

1) Use two questions with a short-text for "Name" only shown if option 3 is selected.

2) Use a multiple-choice-with-comments question, allow only one answer and hide some of the text inputs with JavaScript or CSS.

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: simatz
The topic has been locked.
  • simatz
  • simatz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 3 months ago #192358 by simatz
Replied by simatz on topic Combining two types of questions
Thank you for your answer. Since i'm not a programmer, is there a sample for JavaScript that i can use to do this?
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 3 months ago #192359 by Joffm
Replied by Joffm on topic Combining two types of questions
Hi,
Tony's first option should be obvious.

For the second read this:
www.limesurvey.org/forum/design-issues/1...estion-with-comments

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • simatz
  • simatz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 3 months ago #192360 by simatz
Replied by simatz on topic Combining two types of questions
Thank's a lot!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 3 months ago - 4 years 3 months ago #192361 by tpartner
Replied by tpartner on topic Combining two types of questions
For the second option, to match your screenshot, you would need to place a script like this in the source of a multiple-choice-with-comments question. This script hides some text inputs and renders the question single-choice.

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    var thisQuestion = $('#question{QID}');
 
    // Remove some text inputs
    $('.checkbox-text-item:eq(0) .comment-item', thisQuestion).remove();
    $('.checkbox-text-item:eq(1) .comment-item', thisQuestion).remove();
    $('.checkbox-text-item:last .comment-item', thisQuestion).remove();
 
    // Listener on the checkboxes (exclude all other checkboxes)
    $('.checkbox-text-item :checkbox', thisQuestion).on('change', function(e) {
      if($(this).is(':checked')) {
        $('.checkbox-text-item :checkbox', thisQuestion).not(this).each(function(i) {
          $(this).prop('checked', false);
          $(this).nextAll('input:hidden').val('');
          $(this).closest('li').find('input:text').val('').trigger('keyup');
        });
        $('input.other-text', thisQuestion).val('').trigger('keyup');
      }
    });
 
    // Listener on the "Other" input (exclude all other checkboxes)
    $('input.other-text', thisQuestion).on('keyup change', function(e) {
      if($.trim($(this).val()) != '') {
        $('.checkbox-text-item :checkbox', thisQuestion).each(function(i) {
          $(this).prop('checked', false);
          $(this).nextAll('input:hidden').val('');
          $(this).closest('li').find('input:text').val('').trigger('keyup');
        });
      }
    });
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...2-23.lss
File Size:26 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 3 months ago by tpartner.
The following user(s) said Thank You: cdorin
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose