- Posts: 15
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
$num = rand(0,99); if($num > 0 && $num < 40) { echo '<body style="background-color:red">'; } elseif($num > 41 && $num < 80) { echo '<body style="background-color:blue">'; } else { echo '<body style="background-color:green">'; }
{% set bodyStyle = '' %} {% set randNumber = processString("{rand(1,99)}") %} {% if randNumber < 40 %} {% set bodyStyle = 'background-color:red' %} {% endif %} {% if randNumber >= 40 and randNumber < 80 %} {% set bodyStyle = 'background-color:blue' %} {% endif %} {% if randNumber >= 80 %} {% set bodyStyle = 'background-color:blue' %} {% endif %} <body style="{{ bodyStyle }}" class=" {{ aSurveyInfo.class.body }} font-{{ aSurveyInfo.options.font }} lang-{{aSurveyInfo.languagecode}} {{aSurveyInfo.surveyformat}} {% if( aSurveyInfo.options.brandlogo == "on") %}brand-logo{%endif%}" {{ aSurveyInfo.attr.body }} >
{if(is_empty(Q1), rand(0, 99), Q1)} <script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var num = "{Q1}"; if(num.indexOf('<span') >= 0) { num = num.split('>')[1].split('<')[0]; } var bodyColor; if (num < 40) { bodyColor = 'red'; } else if (num < 80) { bodyColor = 'blue'; } else { bodyColor = 'green'; } $('body').css({ 'background-color': bodyColor }); }); </script>
I might as well add this: I'm working with the List (radio) question type and would love to be able to put one answer on the left of the page and the other on the right.
{if(is_empty(Q1), rand(0, 99), Q1)} <script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var num = "{Q1}"; if(num.indexOf('<span') >= 0) { num = num.split('>')[1].split('<')[0]; } document.body.style.color = "white"; var bodyColor; if (num < 40) { bodyColor = 'darkred'; } else if (num < 80) { bodyColor = 'darkblue'; } else { bodyColor = 'darkgreen'; } $('body').css({ 'background-color': bodyColor }); }); </script>