Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Prefilling Questions with Tokens (converting token value)

Prefilling Questions with Tokens (converting token value) 5 years 8 months ago #57960

  • COMPGURL
  • COMPGURL's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 14
  • Karma: 0
Hello -

I need to populate a question (radio) based on a value stored as a token.
The token attribute stores date of birth information. How can i
convert the token value into a date, then based on the answer,
populate the correct radio option? :blush:

Here's the javascript code i've tried...

<script>
$(document).ready(function()
{
var dob = '{TOKEN:ATTRIBUTE_1}' ;
var convertDate = new Date(dob);
var now = new Date();
var age = Math.round(((now - convertDate)/86400000)/365);

if (age < 18)
{
$('input#answer24178X48X4832').attr('checked', true);
}
else if (age >=18 && age < 50)
{
$('input#answer24178X48X4831').attr('checked', true);
}
else if (age > 49)
{
$('input#answer24178X48X4833').attr('checked', true);
}
}
</script>
Last Edit: 5 years 8 months ago by COMPGURL. Reason: wording
The administrator has disabled public write access.

Prefilling Questions with Tokens (converting token value) 5 years 8 months ago #57969

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6566
  • Thank you received: 1477
  • Karma: 578
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.
Time to create page: 0.440 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form