Check out the LimeSurvey source code on GitHub!

Can I set conditions to compare two text strings in "short text" question types

More
5 years 8 months ago - 5 years 8 months ago #61118 by Haap
Dear all,

After using LimeSurvey for some years now, I have finally a problem that I cannot tackle myself. I've tried some different things, and asked Google and the forum-search for help, but they could not help me either.

I am trying to set a condition to a "short text" question. The case is as follows:
People are asked where they go for shopping
Then they are asked what the nearest shopping centre is.
If these two are not the same, I would like to ask them why, but I cannot achieve that.

My survey-layout is attached, and "live" visible on this website .

I am using LimeSurvey 1.90+ build 9642.

Is what I am trying to do possible, and if so, what's going wrong in my survey structure?
Attachments:
Last Edit: 5 years 8 months ago by Haap. Reason: Typo in title

Please Log in to join the conversation.

More
5 years 8 months ago #61144 by tpartner
This may be a bug.

I can get the conditional question in Group 1 to appear if I add a condition "if Second text does not equal First text":

However, I cannot get the conditional question in Group 2 to appear.

If you need to have a conditional question in Group 2, you could use JavaScript to populate a hidden question in Group 1 and use that question for conditions on Group 2 question(s).

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: Haap

Please Log in to join the conversation.

More
5 years 8 months ago #61187 by Haap
First of all, thanks tpartner! The fix with the SGQA identefier did the trick in this particular survey I'm working on, for the conditional questions are in the same group (and on the same page).

However, how can I decide whether it's a bug, or simply not meant to be possible? To me, it seems a nice addition to LimeSurvey, but I am not at all a LS specialist...

Is the workaround with the hidden question documented somewhere (I was not able to find that)? This might be useful for another user or survey?

Please Log in to join the conversation.

More
5 years 7 months ago #61202 by tpartner

However, how can I decide whether it's a bug, or simply not meant to be possible?

It seems to be a bug to me. Please file a bug report and...

1. Give as much information as possible.

2. Provide step-by-step instructions how to reproduce the problem.

3. If possible/helpful please provide screenshots.

4. Afterwards please post the link to the bugtracker here so we can follow the progress.

Is the workaround with the hidden question documented somewhere (I was not able to find that)? This might be useful for another user or survey?

There are many examples of using hidden questions in the forums but for this particular case I would:

1) Set up your survey to use JavaScript .

2) Add a multiple-options question to the group with a single sub-question (we'll hide this and check the box with JavaScript).

3) Add the following script to the source of the multiple-options question. Replace "11", 22, and 33 with the first short-text, second short-text and multiple-options question IDs respectively.

The script hides the multiple-options question and puts a listener on the short-texts. If text is entered in either and the text in both matches, the checkbox is checked, otherwise it is unchecked. You can then use conditions based on the multiple-options question to show/hide subsequent questions.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		var q1 = 11;
		var q2 = 22;
		var qhidden = 33;
 
		$('#question'+qHidden+'').hide();
 
		$('#question'+q1+' input.text, #question'+q2+' input.text').change(function(){
			if ($('#question'+q1+' input.text').val() && $('#question'+q2+' input.text').val() && $('#question'+q1+' input.text').val() == $('#question'+q2+' input.text').val()) {
				$('#question'+qhidden+' input.checkbox').attr('checked', true);
			}
			else {
				$('#question'+qhidden+' input.checkbox').attr('checked', false); 
			}
		});
	});
 
</script>

Cheers,
Tony Partner

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

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form