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

TOPIC: Populate a question based on previous one

Populate a question based on previous one 10 months 6 days 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 10 months 6 days ago #100076

  • w0928
  • w0928's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 27
  • 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 10 months 6 days 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 10 months 5 days ago #100090

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4071
  • Thank you received: 748
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 10 months 5 days ago by tpartner.
The administrator has disabled public write access.

Populate a question based on previous one 10 months 5 days ago #100092

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1061
  • Thank you received: 234
  • Karma: 74
Hello Tony,

a small typo

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

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
Last Edit: 10 months 5 days ago by Ben_V.
The administrator has disabled public write access.

Populate a question based on previous one 10 months 5 days ago #100093

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4071
  • Thank you received: 748
  • Karma: 341
Thanks Ben :)
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.

Populate a question based on previous one 10 months 5 days ago #100107

  • nfuria
  • nfuria's Avatar
  • OFFLINE
  • Silver Donor
  • 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 10 months 5 days ago #100108

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4071
  • Thank you received: 748
  • Karma: 341
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Populate a question based on previous one 10 months 5 days ago #100110

  • nfuria
  • nfuria's Avatar
  • OFFLINE
  • Silver Donor
  • 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: 10 months 5 days ago by nfuria. Reason: pasted the wrong code
The administrator has disabled public write access.

Populate a question based on previous one 10 months 5 days ago #100112

  • nfuria
  • nfuria's Avatar
  • OFFLINE
  • Silver Donor
  • 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.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.135 seconds
Donation Image