The LimeSurvey Fund-Raiser 2012 is complete. Thank you for donating a total of 25,000 USD!     List of donors »

Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Show a question depending on a rank selection

Show a question depending on a rank selection 2 years 1 month 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 2 years 1 month ago #58939

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 2867
  • Thank you received: 426
  • Karma: 246
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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 2 years 1 month 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 2 years 1 month 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 2 years 1 month ago #58965

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 2867
  • Thank you received: 426
  • Karma: 246
Yup, same approach with different question elements. Gotta love hidden questions!
Cheers,
Tony

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