Welcome, Guest
Username: Password: Remember me

TOPIC: Randomly show question based on previous multiple select answers

Randomly show question based on previous multiple select answers 2 months 2 days ago #111739

  • jefflanzi
  • jefflanzi's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 3
  • Karma: 0
Hello,

I'm trying to create a follow-up question that randomly chooses from one of the selected answers to a previous multiple choice question. The respondent might select all the answers in the multiple choice question, but I only want to have them do the follow-up question for one of the answers, chosen at random.

e.g.

Q1: What fruits have you eaten? [Multiple select]
A1: Apple
A2: Orange
A3: Banana
A4: Grape
A5: Peach
A6: Strawberry

Q2: Please rate your satisfaction with your last [random answer marked Yes from Q1]

Does anyone have a suggestion on how this can be accomplished? Any help or nudges in the right direction would be greatly appreciated.

Thank you!
The administrator has disabled public write access.

Randomly show question based on previous multiple select answers 2 months 2 days ago #111751

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4266
  • Thank you received: 803
  • Karma: 368
Are the questions on the same or separate pages?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Randomly show question based on previous multiple select answers 2 months 2 days ago #111752

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5331
  • Thank you received: 296
  • Karma: 249
There are no existing features for this but if questions are on the same page, Tony might help out with some JavaScript magic :-)

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Randomly show question based on previous multiple select answers 2 months 2 days ago #111760

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4266
  • Thank you received: 803
  • Karma: 368
If the questions are on the same page...

1) Directly after Q1, insert a copy of Q1 which has random answer order and is filtered by Q1.

2) Filter Q2 by the hidden question.

3) Add the following script to the hidden question. This will put a listener on Q1 so, when changes are detected, only the first visible checkbox of the hidden question is checked. This effectively displays a single random row of Q2, filtered on Q1 while accommodating a "mandatory" setting on Q2.

<script type="text/javascript" charset="utf-8">	
    $(document).ready(function(){
 
		// Identify the questions
		var qHidden = $('#question{QID}');
		var q1 = $(qHidden).prevAll('.multiple-opt:eq(0)');
 
		// Hide the hidden question
		$(qHidden).css({
			'position': 'absolute',
			'left': '-999em',
			'height': '0'
		})
 
		// Listener on Q1
		$('input.checkbox', q1).click(function(event){
			// Reset the hidden question
			$('input.checkbox', qHidden).each(function(i) {
				$(this).prop('checked', false);
				checkconditions($(this).attr('value'), $(this).attr('name'), $(this).attr('type'));
			});			
 
			// Check the first visible box in the hidden question
			var firstItem = $('li.question-item:visible:eq(0) input.checkbox', qHidden);
			$(firstItem).click();
		});
	});
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey_survey_673563_2014-08-19.lss
File Size: 29 KB
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Randomly show question based on previous multiple select answers 2 months 1 day ago #111774

  • jefflanzi
  • jefflanzi's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 3
  • Karma: 0
Wow that looks great thanks! The questions are currently on separate pages, but I'll do some rearranging to give that JavaScript a shot.

My other idea was to create a separate question for each answer option and place them in their own randomized question group. Then use relevance equations to only show each question if it's corresponding box was checked in Q1, and if no other questions in the group have been answered yet. This seems like it would allow me to keep the questions on separate pages, but I'm still going through the EM documentation to get this figured out.

I also tried using an equation question to randomly determine which question to display, but I couldn't figure out how to save the checked boxes from the previous question into some kind of array or list variable and select only from those.

I'll keep working on all these solutions and let you guys know how it turns out. Thank you again for the help!
The administrator has disabled public write access.

Randomly show question based on previous multiple select answers 2 months 1 day ago #111775

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4266
  • Thank you received: 803
  • Karma: 368
If on separate pages, you should be able to follow the instructions above but place the hidden question on the same page as Q2 and use this script instead (not tested):

<script type="text/javascript" charset="utf-8">	
    $(document).ready(function(){
 
		// Identify the questions
		var qHidden = $('#question{QID}');
 
		// Hide the hidden question
		$(qHidden).css({
			'position': 'absolute',
			'left': '-999em',
			'height': '0'
		})
 
		// Reset the hidden question
		$('input.checkbox', qHidden).each(function(i) {
			$(this).prop('checked', false);
			checkconditions($(this).attr('value'), $(this).attr('name'), $(this).attr('type'));
		});			
 
		// Check the first visible box in the hidden question
		var firstItem = $('li.question-item:visible:eq(0) input.checkbox', qHidden);
		$(firstItem).click();
	});
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.124 seconds
Donation Image