Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Populate a question based on previous one

Populate a question based on previous one 2 years 10 months ago #100075

  • victorgil
  • victorgil's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
Hi

First of all, I have to say that I've been looking for an answer (forum, google...) before asking you :( I'll explain my problem briefly

Page 1. Question 1. Age (Number)
Page 2. Question 2. Age Group (Hidden question that I need to set quotas and screen outs)
- Subquestion 1. <20
- Subquestion 2. >20

Have you an idea how to do this? I have to say that I'm a newbie

Many thanks in advance
The administrator has disabled public write access.

Populate a question based on previous one 2 years 10 months ago #100076

  • w0928
  • w0928's Avatar
  • Offline
  • Junior Lime
  • Posts: 36
  • Thank you received: 3
  • Karma: 1
When you say 'populate a question'... do you mean show a question or pre-populate the answer to the question?

If it is the former, have you tried having 2 "question 2s" and showing one when question 1 has an answer of <20 and showing the other when question 1 has an answer > 20?

If it is the latter, I'm pretty sure there is a WorkAround in the manual that describes how to do that.
The administrator has disabled public write access.

Populate a question based on previous one 2 years 10 months ago #100078

  • victorgil
  • victorgil's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
Many thanks whowe1 I mean pre-populate the answer of question 2. For example, If a respondent write 24 in question 1, then question 2 should be auto-checked as >20 (years old). I've spent all this evening a WorkAround in the manual and forum post, but I didn't find an example to use. Maybe I am not looking for correctly, but....I have nothing :( Thanks a lot for your support.
The administrator has disabled public write access.

Populate a question based on previous one 2 years 10 months ago #100090

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6128
  • Thank you received: 1360
  • Karma: 535
Assuming:
1) the question code for the first question is "age"
2) the second question is a select-radio type
3) the second question is NOT hidden with the advanced setting

Try adding this to the source of the second question (not tested)
<script type="text/javascript" charset="utf-8">	
	$(document).ready(function() {	
 
		$('#question{QID}').hide();
 
		var age = '{age.shown}';
 
		if(age < 20) {
			$('#question{QID} input.radio:eq(0)').trigger('click');
		}
		else {
			$('#question{QID} input.radio:eq(1)').trigger('click');
		}
	});
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 2 years 10 months ago by tpartner.
The administrator has disabled public write access.

Populate a question based on previous one 2 years 10 months ago #100092

  • Ben_V
  • Ben_V's Avatar
  • Offline
  • Platinum Lime
  • Posts: 1797
  • Thank you received: 439
  • Karma: 110
Hello Tony,

a small typo

var age = '{age.shown}' :
var age = '{age.shown}' ;
Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
All LS releases => bit.ly/1VMuTDu | 2.06lts => bit.ly/1Qv44A1
Demo surveys => bit.ly/20NW9V8 (already included in /docs/demosurveys)
Last Edit: 2 years 10 months ago by Ben_V.
The administrator has disabled public write access.

Populate a question based on previous one 2 years 10 months ago #100093

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6128
  • Thank you received: 1360
  • Karma: 535
Thanks Ben :)
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Populate a question based on previous one 2 years 10 months ago #100107

  • nfuria
  • nfuria's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 14
  • Thank you received: 1
  • Karma: 1
I tested but it doesn't works.
First the console report a "Unexpected identifier" at the line of the var age, as it becomes:

var age = '<span id='LEMtailor_Q_8707_49'></span>';

I change the script to include the var in double quotes:

var age = "{age.shown}";

With this change there are no error but the script doesn't works.

Attached the survey structure.

File Attachment:

File Name: hbc70170.lss
File Size:13 KB
The administrator has disabled public write access.

Populate a question based on previous one 2 years 10 months ago #100108

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6128
  • Thank you received: 1360
  • Karma: 535
What is the question code for your age question?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Populate a question based on previous one 2 years 10 months ago #100110

  • nfuria
  • nfuria's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 14
  • Thank you received: 1
  • Karma: 1
The code is "age".
The second question:
Selection:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#question{QID}').hide();
var age = "{age.shown}";
console.log(age);
if(age < 20) {
$('#question{QID} input.radio:eq(0)').trigger('click');
}
else {
$('#question{QID} input.radio:eq(1)').trigger('click');
}
});
</script>
Last Edit: 2 years 10 months ago by nfuria. Reason: pasted the wrong code
The administrator has disabled public write access.

Populate a question based on previous one 2 years 10 months ago #100112

  • nfuria
  • nfuria's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 14
  • Thank you received: 1
  • Karma: 1
The attachment I upload before has the single quotes in the "var age" and thus cause the "unexpected identifier" error.
The administrator has disabled public write access.

Populate a question based on previous one 2 years 10 months ago #100122

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6128
  • Thank you received: 1360
  • Karma: 535
You initially said these questions are on different pages but the sample survey has them on the same page. Which do you need?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Populate a question based on previous one 2 years 10 months ago #100127

  • nfuria
  • nfuria's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 14
  • Thank you received: 1
  • Karma: 1
The original question is posted by another user.
I tested the solution posted presuming that the hidden question can stay in the same page.
Now I change the format of the survey to "Question by question" and it works.
Also, it works with single or double quotes in var age.

Actually I tested because I had a similar situation but I need that the question stay in the same page.
Are there some solution?
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.304 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form