Populate a question based on previous one

More
3 years 6 months ago #100075 by victorgil
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

Please Log in to join the conversation.

More
3 years 6 months ago #100076 by w0928
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.

Please Log in to join the conversation.

More
3 years 6 months ago #100078 by victorgil
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.

Please Log in to join the conversation.

More
3 years 5 months ago - 3 years 5 months ago #100090 by tpartner
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: 3 years 5 months ago by tpartner.

Please Log in to join the conversation.

More
3 years 5 months ago - 3 years 5 months ago #100092 by Ben_V
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
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last Edit: 3 years 5 months ago by Ben_V.

Please Log in to join the conversation.

More
3 years 5 months ago #100093 by tpartner
Thanks Ben :)

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.

More
3 years 5 months ago #100107 by nfuria
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
Attachments:

Please Log in to join the conversation.

More
3 years 5 months ago #100108 by tpartner
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.

Please Log in to join the conversation.

More
3 years 5 months ago - 3 years 5 months ago #100110 by nfuria
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: 3 years 5 months ago by nfuria. Reason: pasted the wrong code

Please Log in to join the conversation.

More
3 years 5 months ago #100112 by nfuria
The attachment I upload before has the single quotes in the "var age" and thus cause the "unexpected identifier" error.

Please Log in to join the conversation.

More
3 years 5 months ago #100122 by tpartner
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.

Please Log in to join the conversation.

More
3 years 5 months ago #100127 by nfuria
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?

Please Log in to join the conversation.