Welcome, Guest
Username: Password: Remember me

TOPIC: Prefilling Questions with Tokens (converting token value)

Prefilling Questions with Tokens (converting token value) 3 years 4 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: 3 years 4 months ago by COMPGURL. Reason: wording
The administrator has disabled public write access.

Re: Prefilling Questions with Tokens (converting token value) 3 years 4 months ago #57969

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4072
  • Thank you received: 748
  • Karma: 341
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.
Moderators: ITEd
Time to create page: 0.107 seconds
Donation Image