Check out the LimeSurvey source code on GitHub!

Prefilling Questions with Tokens (converting token value)

More
5 years 11 months ago - 5 years 11 months ago #57960 by COMPGURL
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 11 months ago by COMPGURL. Reason: wording

Please Log in to join the conversation.

More
5 years 11 months ago #57969 by tpartner

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form