Welcome, Guest
Username: Password: Remember me

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

'Pre-populated' type answers not recorded in response data 1 year 2 months ago #96122

  • jlaunay
  • jlaunay's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
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() {
$('#answer62795X59X1377').val(age);
});
}
else
{
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() {
$('#answer62795X59X1377').val(options[randomnumber]);
});
}
</script>

And I'm using version 1.92. Thanks!
The administrator has disabled public write access.

'Pre-populated' type answers not recorded in response data 1 year 2 months ago #96221

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6236
  • Thank you received: 794
  • Karma: 238
Hello,

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

Denis
The administrator has disabled public write access.
The following user(s) said Thank You: jlaunay

'Pre-populated' type answers not recorded in response data 1 year 2 months ago #96226

  • jlaunay
  • jlaunay's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
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!
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.107 seconds
Donation Image