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

TOPIC: Answers filtered by previous question answers

Answers filtered by previous question answers 2 years 8 months ago #69167

  • crescentio
  • crescentio's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Hello

I'm a Limesurvey newbie and I want to make questions wich answers are filtered by the answer of previous questions, for example:

Q1 Country Single Choice List (Radio)
B Bolivia
C Colombia
E Ecuador

Q2 State Single Choice List (Dropdown)
BBE Beni
BCH Chuquisaca
BCO Cochabamba
CAT Atlantico
CCU Cundinamarca
CSA Santander

Q3 City Single Choice List (Dropdown)
BBELO Loreto
BBEMA Magdalena
BCHSU Sucre
BCHTA Tarabuto

In Q2 must appear just the options that are related to the answer in Q1, if Bolivia was choosen, in Q2 must appear just Beni, Chuquisaca and Cochabamba, and if Beni was choosen in Q2 must appear Loreto and Magdalena in the options of Q3.

I've tried to do work with this workaround but not succesful. My knowledge of javascript is minimum, and don't know why the workaround is not working.
My survey is configurated as "question by question".

Thanks in advance,
sorry for my bad english :(
The administrator has disabled public write access.

Re: Answers filtered by previous question answers 2 years 8 months ago #69177

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5300
  • Thank you received: 291
  • Karma: 247
You can use conditions but it will be a little complex. You need several following questions like
Q2a (Bolivia): <states>
Q2b (Columbia): <states>
...

Q3a1 (Beni): <cities>
Q3a2 (Chuquisaca): <cities>

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Answers filtered by previous question answers 2 years 8 months ago #69211

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4049
  • Thank you received: 739
  • Karma: 341
You should be able to use JavaScript and {INSERTANS} to find the first letter(s) of the previous answer(s) and only show options with codes that start with those letters.

Can you attach a sample survey with those 3 questions.

T.
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: Answers filtered by previous question answers 2 years 8 months ago #69224

  • crescentio
  • crescentio's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Thanks Marcel and Tony for your help

Marcel, your solution looks ok but it could make the survey a little bit complex, too many questions, and don't know how this solution could affect the statistical analisys. I want to try the solution with javascript and if it doesn't work I'll use your solution.

Tony, I've tested javascript with an alert and it works, but the {INSERTANS} don't know how to test it. I've attached a sample survey with the javascript codes in the questions.

Thanks again

File Attachment:

File Name: limesurvey_survey_47126.lss
File Size: 33 KB
The administrator has disabled public write access.

Re: Answers filtered by previous question answers 2 years 8 months ago #69250

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4049
  • Thank you received: 739
  • Karma: 341
Another more portable way of handling this may be to use text inputs with the jQuery autocomplete workaround. The data source for autocomplete (list of states or cities) could be defined depending on the previous answers.

Having said that, here is my suggestion for your particular case. I wouldn't use the workaround you are trying - I think it's overkill for what you need.

Add this script to the source of the "State" question. You will need to use the correct <a href='www.docs.limesurvey.org/tiki-index.php?p...tions+for+LimeSurvey'>SGQA</a> values for your survey. I think the comments explain it well enough:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Get the countryCode (first character of the country)
		var countryCode = '{INSERTANS:47126X993X12555}'.substr(0, 1).toUpperCase();
 
		// Loop through all dropdown options and remove those with codes not starting with the countryCode
		$('select[id^="answer"] option').each(function(i){
			if($(this).attr('value')  && $(this).attr('value').substr(0, 1).toUpperCase() != countryCode) {
				$(this).remove();
			}
		});
	});
</script>

Add this to the source of the "City" question. You will need to use the correct <a href='www.docs.limesurvey.org/tiki-index.php?p...tions+for+LimeSurvey'>SGQA</a> values for your survey:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Get the countryCode (first character of the country)
		var countryCode = '{INSERTANS:47126X993X12555}'.substr(0, 1).toUpperCase();
		// Get the stateCode (first 2 characters of the state)
		var stateCode = '{INSERTANS:47126X993X12556}'.substr(0, 2).toUpperCase();
 
		// Concatenate the two codes
		var fullCode = countryCode + stateCode;
 
		// Loop through all dropdown options and remove those with codes not starting with the fullCode
		$('select[id^="answer"] option').each(function(i){
			if($(this).attr('value')  && $(this).attr('value').substr(0, 3).toUpperCase() != fullCode) {
				$(this).remove();
			}
		});
	});
</script>

Here is a working sample survey:

Attachment limesurvey_survey_47126_TONY.lss not found

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: 2 years 8 months ago by tpartner. Reason: Typo
The administrator has disabled public write access.

Re: Answers filtered by previous question answers 2 years 8 months ago #69251

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4049
  • Thank you received: 739
  • Karma: 341
Hmm, the file didn't upload. Here it is:

File Attachment:

File Name: limesurvey_survey_47126_v2.lss
File Size: 34 KB
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: Answers filtered by previous question answers 2 years 8 months ago #69403

  • crescentio
  • crescentio's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 15
  • Karma: 0
Thank you so much Tony, it worked very good :laugh:

I have a last question: is it possible to get answer options from an external database through SQL querys?
The administrator has disabled public write access.

Re: Answers filtered by previous question answers 2 years 8 months ago #69405

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5300
  • Thank you received: 291
  • Karma: 247
Here it gets rather complicated. Technically that is possible by using an Ajax call and some Javascript to replace answer text dummies if this is what you are up to?!

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Answers filtered by previous question answers 2 years 8 months ago #69407

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4049
  • Thank you received: 739
  • Karma: 341
Yes, as I mentioned earlier, you could use the AutoComplete plugin to present a dropdown list of states or cities. The dropdown would be used to load a text input.

The data source for the dropdown could be CSV file or an AJAX call to an external PHP script that queries a database and returns the appropriate list.

Personally, I would go with the CSV method. I think it would be easier to maintain. It would be a modification of this workaround - docs.limesurvey.org/Workarounds%3A+Manip...ulate_several_fields
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: Answers filtered by previous question answers 2 years 4 months ago #75639

  • hrshdhgd
  • hrshdhgd's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 29
  • Karma: 0
Hello all,

I had a question related to this one but not exactly the same. I understand the logic of making questions appear depending on the answers of the previously asked questions. What if I wanted the options of a question to appear only if they were checked in the previous question.

for eg:

Which options do you like?
a) A
b) B
c) C
d) D

say if I choose C and D, I want the next question to show as:

Which is your favorite amongst the following: (choose any 1)
a) C
b) D

Thanks in advance!
Last Edit: 2 years 4 months ago by hrshdhgd.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.147 seconds
Donation Image