Check out the LimeSurvey source code on GitHub!

prefill not working

More
5 years 3 months ago #69248 by bwoo5
I have a radio button question with 2 answers, 1 and 2 and it is hidden from the survey participant and needs to be filled in from a token field. The next page is supposed to show questions based (conditional) on the radio button question. I used the code below that was posted in the forums and adapated it to my survey but it is not prefilling in the radio button. Has the way this code works changed since then (8 months ago)?

<script type="text/javascript" charset="utf-8">$(document).ready(function() {if('{TOKEN:ATTRIBUTE_2}' == 'VZW') {$("input#answer74931X156X885X1").attr('checked', true);}if('{TOKEN:ATTRIBUTE_2}' == 'FV') {$("input#answer74931X156X885X2").attr('checked', true);}if('{TOKEN:ATTRIBUTE_2}' == 'BVBA') {$("input#answer74931X156X885X3").attr('checked', true);}if('{TOKEN:ATTRIBUTE_2}' == 'NG') {$("input#answer74931X156X885X4").attr('checked', true);}if('{TOKEN:ATTRIBUTE_2}' == 'NV') {$("input#answer74931X156X885X5").attr('checked', true);}if('{TOKEN:ATTRIBUTE_2}' == 'CommV') {$("input#answer74931X156X885X6").attr('checked', true);}if('{TOKEN:ATTRIBUTE_2}' == 'Eenmanszaak') {$("input#answer74931X156X885X7").attr('checked', true);}});</script>

Please Log in to join the conversation.

More
5 years 3 months ago #69254 by tpartner
The SGQA values don't look correct - you have an extra "X" in them.

What are:
- the survey ID?
- The group ID?
- The radio question ID?
- The radio question answer codes?

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
5 years 3 months ago #69255 by bwoo5
What are:
- the survey ID? 54718
- The group ID? 217
- The radio question ID? 1679
- The radio question answer codes? 1 and 2

I got the code from this post

www.limesurvey.org/en/forum/can-i-do-thi...it=10&start=10#57392

Thanks!

Please Log in to join the conversation.

More
5 years 3 months ago #69257 by tpartner

The radio question answer codes? 1 and 2

But that code (aside from the SGQA errors) is to set a radio with 7 answers based on the value of token custom ATTRIBUTE_2.

Which token custom attribute do you need to read and what value(s) are to set radio 1 and what value(s) are to set radio 2?

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
5 years 3 months ago #69260 by bwoo5
the code for the radio button is 2. Sorry I mean there is 2 answers, 1 and 2. i am only using 1 attribute, attribute_1 which I have called "position". So the radio button if showing would ask, what is your position and have the 2 choices. The values in the token field are either 1 or 2 for the position.

Thanks.

Please Log in to join the conversation.

More
5 years 3 months ago #69262 by tpartner
Okay then, if I have read everything right, the script should be:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		if('{TOKEN:ATTRIBUTE_1}' == '1') {
			$("input#answer54718X217X16791").attr('checked', true);
		}
		if('{TOKEN:ATTRIBUTE_1}' == '2') {
			$("input#answer54718X217X16792").attr('checked', true);
		}
	});
</script>

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
5 years 3 months ago #69285 by bwoo5
Thanks tpartner,

So that extra x was the thing that was messing it up for me. works great now.

Please Log in to join the conversation.

More
5 years 3 months ago #69321 by Mazi
Do we already have a feature request for prefilling answers based ion token values?


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 3 months ago #69324 by tpartner
I think TMSWhite said this could be handled with Expression Manager.

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
5 years 3 months ago #69334 by TMSWhite
Yes, Expression Manager (EM) will let you do this, provided you make one small change.

EM doesn't currently set default responses for other questions (although that is a possible enhancement).

However, it sounds as though you just want to be able to use response values to do conditional logic. In that case, you can create an "Equation" question type with the desired value, and use the value in that Equation to drive the conditional logic for the subsequent questions.

If you can give more details about what you are trying to accomplish, I can elaborate.

In the interim, you can see some examples here .

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form