'Pre-populated' type answers not recorded in response data

4 years 6 months ago #96122 by jlaunay
jlaunay created the topic: 'Pre-populated' type answers not recorded in response data
Hi, I'm doing something that probably requires some workaround so I was wondering if you could help.

My survey involves some answers that are generated 'randomly' using some javascript, which are then displayed to users, and saved by the system, using the ${'#answerQQ').val(myrandomanswer) method. I know that these answers are being saved correctly, because if I insert the answers (e.g. {INSERTANS:QQ} ) into one of the subsequent question pages it works fine.

However, the answers that are recorded in the response data are not so fine.... All that gets saved is the first letter of the response. I thought perhaps I had to convert the answers into a different data type (e.g. string), but that didn't seem to help. I also thought perhaps it could be because the question type I'm using for the generated responses is 'text display', but I've tried changing it to something more like a normal question response (long text answer), and that didn't work.

This is an example of how I am 'randomly' generating answers (my first go at javascript so probably not the most efficient!), which should help you understand how the answers are being saved... The point is that I'm displaying an age to the user, which is either different from their age (which they give at question 1382), or is the same as their age. Whether it is the same or different is determined by a binary list generated at question 1374. The current question is 1377.

<script type="text/javascript" charset="utf-8">
var randvars = new Array();
randvars = {INSERTANS:62795X58X1382};
var age = "{INSERTANS:62795X58X1374}";
if(randvars[1] == 1)
document.write("Age: ", age);
$(document).ready(function() {
var options = new Array();
options[0] = '18-25 years';
options[1] = '26-35 years';
options[2] = '36-45 years';
options[3] = '46-55 years';
options[4] = '55+ years';
var index = options.indexOf(age);
options.splice(index, 1);
var randomnumber=Math.floor(Math.random()*4);
document.write("Age: ", options[randomnumber]);
$(document).ready(function() {

And I'm using version 1.92. Thanks!

Please Log in to join the conversation.

4 years 5 months ago #96221 by DenisChenu
DenisChenu replied the topic: 'Pre-populated' type answers not recorded in response data

Bolierplate question type are not the good way for this .

Use directly an equation question type, and fill it with Expression Manager : manual.limesurvey.org/Expression_Manager


Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
The following user(s) said Thank You: jlaunay

Please Log in to join the conversation.

4 years 5 months ago #96226 by jlaunay
jlaunay replied the topic: 'Pre-populated' type answers not recorded in response data
Hi, thanks for this. The programming required seemed to be a bit too much for Expression Manager (it required list type variables, and I couldn't see a way of doing this with Expression Manager, or an alternative to using lists). So I have left the javascript that determines the random answer as it is, but then created a hidden equation later in the survey, which directly takes the earlier (calculated) answer as it's input. The answer reported from the boilerplate question is still nonsense, but the one reported by the hidden equation is good, so it all works okay in the end. Thanks for letting me know that equations were the best way to record this information!

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!