Welcome, Guest
Username: Password: Remember me

TOPIC: prefill not working

prefill not working 2 years 9 months ago #69248

  • bwoo5
  • bwoo5's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 80
  • Thank you received: 4
  • Karma: 0
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>
The administrator has disabled public write access.

Re: prefill not working 2 years 9 months ago #69254

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4118
  • Thank you received: 760
  • Karma: 346
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.

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: prefill not working 2 years 9 months ago #69255

  • bwoo5
  • bwoo5's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 80
  • Thank you received: 4
  • Karma: 0
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!
The administrator has disabled public write access.

Re: prefill not working 2 years 9 months ago #69257

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4118
  • Thank you received: 760
  • Karma: 346
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.

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: prefill not working 2 years 9 months ago #69260

  • bwoo5
  • bwoo5's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 80
  • Thank you received: 4
  • Karma: 0
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.
The administrator has disabled public write access.

Re: prefill not working 2 years 9 months ago #69262

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4118
  • Thank you received: 760
  • Karma: 346
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.

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: prefill not working 2 years 9 months ago #69285

  • bwoo5
  • bwoo5's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 80
  • Thank you received: 4
  • Karma: 0
Thanks tpartner,

So that extra x was the thing that was messing it up for me. works great now.
The administrator has disabled public write access.

Re: prefill not working 2 years 9 months ago #69321

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 293
  • Karma: 248
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)limesurvey.org'"
The administrator has disabled public write access.

Re: prefill not working 2 years 9 months ago #69324

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4118
  • Thank you received: 760
  • Karma: 346
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.

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: prefill not working 2 years 9 months ago #69334

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
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.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.143 seconds
Donation Image