Welcome, Guest
Username: Password: Remember me

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

Can I set conditions to compare two text strings in "short text" question types 2 years 11 months ago #61118

  • Haap
  • Haap's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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: 2 years 11 months ago by Haap. Reason: Typo in title
The administrator has disabled public write access.

Re: Can I set conditions to compare two text strings in "short text" question types 2 years 11 months ago #61144

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3844
  • Thank you received: 690
  • Karma: 330
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":
Capture3.JPG


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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: Haap

Re: Can I set conditions to compare two text strings in "short text" question types 2 years 11 months ago #61187

  • Haap
  • Haap's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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?
The administrator has disabled public write access.

Re: Can I set conditions to compare two text strings in "short text" question types 2 years 11 months ago #61202

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3844
  • Thank you received: 690
  • Karma: 330
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.

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.116 seconds
Donation Image