Welcome, Guest
Username: Password: Remember me

TOPIC: Show a question depending on a rank selection

Show a question depending on a rank selection 3 years 5 months ago #58864

  • thomasw
  • thomasw's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
I have a ranking selection. I want to show a follow-up question if the user has chosen one (or two in this case) specific items, but independent from the rank position.

Example:
Q1 How do you want to access your emails? (please rank)
IMAP mailbox
Webmailer
POP3 mailbox
Forward to an existing account

Q2 You have chosen a mailbox type in your ranking. Are you familiar with setting up a mailbox in your mail program?
(x) I can set up a mailbox in my mail program on my own
( ) I need help setting up a mailbox in my mail program

So, Q2 should only appear if a mailbox (IMAP or POP3) was selected in Q1, but independent from the actual rank position. Is that possible?
The administrator has disabled public write access.

Re: Show a question depending on a rank selection 3 years 5 months ago #58939

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4134
  • Thank you received: 765
  • Karma: 347
This should do the trick if all questions are on the same page.

1) Set up your survey to use JavaScript.

2) Create the ranking question (qRank).

3) Create a short-text question (we'll call it qHidden and hide it with JavaScript later).

4) Create your conditional question (q2) and make it conditional on qHidden = 1.

5) Add the following script to the source of one of the questions or help text. Replace the following parameters in line 5-7:
- RR = your qRank ID
- HH = your qHidden ID
-'IMAP mailbox', 'POP3 mailbox' = The answers that will cause q2 to be shown
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		var qRankID = RR;
		var qHiddenID = HH;
		var optionArr = ['IMAP mailbox', 'POP3 mailbox']; // List of ranked options to display Q2
 
		// Hide the hidden question
		$('#question'+qHiddenID).hide();
 
		// A listener on the ranking elements
		$('#question'+qRankID+' td.label select, #question'+qRankID+' td.output img').click(function() {
 
			var show = 0;
 
			// Find if any of the options are in the ranked column
			$('#question'+qRankID+' td.output input.text').each(function(i) {
				var inputVal = $(this).val();				
 
				$.each(optionArr, function(index, value) { 
					if(value == inputVal) {
						show = 1;
					} 
				});
			});
 
			// Populate qHidden depending if any of the options are in the ranked column
			$('#question'+qHiddenID+' input.text').val(show);
 
			// Fire the conditions function
			var hiddenInputValue = $('#question'+qHiddenID+' input.text').val();
			var hiddenInputName = $('#question'+qHiddenID+' input.text').attr('name');
			var hiddenInputType = $('#question'+qHiddenID+' input.text').attr('type');
			checkconditions(hiddenInputValue, hiddenInputName, hiddenInputType);
		});
 
	});
 
</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.
Last Edit: 3 years 5 months ago by tpartner.
The administrator has disabled public write access.
The following user(s) said Thank You: thomasw

Aw: Re: Show a question depending on a rank selection 3 years 5 months ago #58964

  • thomasw
  • thomasw's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
Great. The approach seems to be similar to my other question. The qHidden question, the condition, ...
I'll see whether I can solve my next problem on my own.
The administrator has disabled public write access.

Re: Aw: Re: Show a question depending on a rank selection 3 years 5 months ago #58965

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4134
  • Thank you received: 765
  • Karma: 347
Yup, same approach with different question elements. Gotta love hidden questions!
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.150 seconds
Donation Image