Welcome, Guest
Username: Password: Remember me

TOPIC: Conditional Selection

Conditional Selection 2 years 8 months ago #70994

  • uxexp
  • uxexp's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 19
  • Karma: 0
Hi Experts,
I have a multiple choice questions with following non-random answer options:

A
B
C
D

Next, I display slider scales based on the selection above.

What I want is this:
1. If I select A and any other option except B, capture the label for option A in a hidden text box
2. If I select B (and any other option except A), capture the label for option B in a hidden text box
3. If I select both A and B, then check and compare the slider ratings for A and B and capture the one with the highest rating in the hidden text box
4. If I just select C and no other option, capture label for C
5. If I select D and no other option, capture D
6. If I select C and D capture C again.

In short, if options A and B are selected, check their respective slider ratings and pick the highest. For all other selections, simply pick the first checked label in the list.

I have created a sample survey here:

coolsurvey.limequery.com/49132/lang-en

Can anyone help?

Thanks
Last Edit: 2 years 8 months ago by uxexp.
The administrator has disabled public write access.

Re: Conditional Selection 2 years 8 months ago #71004

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4120
  • Thank you received: 760
  • Karma: 346
That shouldn't be too hard but I think you missed a scenario:

What if checkboxes A and B are selected and slider A = slider B?
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.

Re: Conditional Selection 2 years 8 months ago #71031

  • uxexp
  • uxexp's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 19
  • Karma: 0
Good catch! In that case, I would go with option "A". So, if A and B are selected and slider value of A=B, select B only if B>A.

I was able to capture all the selected items from the multiple choice question in an array but this is where I had to stop because I am not skilled at this. I didn't know how to then take items A and B from the array and check for the slider values. I have some vague idea about the logic

1) Create an array of selected items, add selected items from the multiple choice to this array sequentially
2) if the first item in the array is A then check if second item is B, it not capture label for A.
3) If yes, then compare slider value of A to that of B and capture the label
4) If first item is not A then simply capture the label for the first item in the array (i.e. arrary[0])

Any help?
Last Edit: 2 years 8 months ago by uxexp.
The administrator has disabled public write access.

Re: Conditional Selection 2 years 8 months ago #71037

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4120
  • Thank you received: 760
  • Karma: 346
Okay, just to be clear, if slider A = slider B, then "A" is loaded into the hidden short-text.

The array approach may work but here's what I came up with:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Hide the short-text question
		$('.text-short').hide();
 
		// Interrupt next/submit function 
		$('#movenextbtn, #movesubmitbtn').click(function(){
 
			var label;
 
			// "A" and "B" selected
			if($('input.checkbox:eq(0)').attr('checked') == true && $('input.checkbox:eq(1)').attr('checked') == true) {
				// Slider A < slider B
				if(Number($('.multinum-slider:eq(0) .text').val()) < Number($('.multinum-slider:eq(1) .text').val())) {
					label = $('.multiple-opt label:eq(1)').text();
				}
				// Slider A >= slider B
				else {
					label = $('.multiple-opt label:eq(0)').text();
				}
			}
			// "A" selected
			else if($('input.checkbox:eq(0)').attr('checked') == true) {
				label = $('.multiple-opt label:eq(0)').text();
			}
			// "B" selected
			else if($('input.checkbox:eq(1)').attr('checked') == true) {
				label = $('.multiple-opt label:eq(1)').text();
			}
			// "C" selected
			else if($('input.checkbox:eq(2)').attr('checked') == true) {
				label = $('.multiple-opt label:eq(2)').text();
			}
			// "D" selected
			else if($('input.checkbox:eq(3)').attr('checked') == true) {
				label = $('.multiple-opt label:eq(3)').text();
			}
 
			$('.text-short input.text').val(label);
 
			return true;
 
 
		});
 
	});
 
</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.

Re: Conditional Selection 2 years 8 months ago #71044

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
uxexp-

Here's how you could do that in LimeSurvey 1.92. Note that I neglected to look at you demo first, so I used a multiple numerical input question style for the sliders. However, this general approach would work to get the correct label value.

Here is the sample group:

File Attachment:

File Name: limesurvey_group_169.lsg
File Size: 17 KB


Here's what it looks like running:

group-preview.png


And here's the re-order question view, which makes it easy to see the Expression in the Equation question type (Label) which generates the proper label based upon the input values:

group-reorder.png


As you can see, it uses a nested set of if(test,answer_if_true,answer_if_false) equations to test each of the conditions you wanted; and returns the display value for the label (which in this case is X.question).

Somehow an extra colon (%3A) got into the selector for the .question value, but that should be an easy fix.

/Tom
The administrator has disabled public write access.

Re: Conditional Selection 2 years 8 months ago #71051

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
uxexp-

Here's a working version of what you're seeking using 1.92 RC1. I felt it was worth posting this, since the required equation is a little bit different when you are dealing with conditional questions. As you'll see, since you are accessing the values of the sliders, you need to use the .NAOK suffix so that the equation generates a result even if either of those two sliders is irrelevant. Without using .NAOK, the default is to have the value always be false/blank if any of the contributing variables are irrelevant.

Here is the updated group:

File Attachment:

File Name: limesurvey_group_169_2011-12-17.lsg
File Size: 30 KB


Here is the updated "Change question order" view that shows the revised Equation to generate the Label. It also shows the relevance equations to conditionally show Products A-D based upon your choices for the Multiple Choice (MC) question:

group-reorder2.png

Since the screenshot isn't attaching, here is the updated equation to ensure that Label has the desired value:
{if((MC_A == 'Y' and MC_B == 'Y'), if(sA_1.NAOK >= sB_1.NAOK, MC_A.question, MC_B.question), if(MC_A == 'Y', MC_A.question, if(MC_B == 'Y', MC_B.question, if(MC_C == 'Y', MC_C.question, if(MC_D == 'Y', MC_D.question, '')))))}

And here is a working preview of that group, showing that you get the hidden value of "B" for Label if you select A and B and the slider value of B is > that for A.

group-preview_2011-12-17.png


You can find more details about how to do this on the Expression Manager reference and HowTos pages.

/Tom
Last Edit: 2 years 8 months ago by TMSWhite.
The administrator has disabled public write access.

Re: Conditional Selection 2 years 8 months ago #71134

  • uxexp
  • uxexp's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 19
  • Karma: 0
Thank you all. This is exactly what I wanted.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.175 seconds
Donation Image