I have a survey with 90 questions with each having 5 answers with radio buttons for making a selection. I would like to place a button at the very top of the survey and make it easy for the survey takers to make the same selection (pick 1 radio button out of the 5) for the 90 questions.
Is this possible with LimeSurvey and if so, please guide me on how to achieve this. Thanks in advance for your help.
I used the following code within the question source and it worked. I am able to use the selection for a question answer to set the remaining questions radio button choices:
I would hate to copy/paste this code in 90+ questions, so I added it to the script/template.js file. But the code does not work there - it is not able to find the selection for question code G2Q1N and gives a 'Undefined variable' error. What is the proper way to find the selected choose for the radio button on question code G2Q1N?
You cannot access Expression Manager variables directly from template.js. I suppose you could place that script in question.pstpl but you would need to add some sort of condition to ensure it only affects the appropriate questions.
Cheers,
Tony Partner Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Thank you very much for helping me out with a code snippet. I checked the
LimeSurvey manual
and found the full list of question classes. The class for Array (5 point choice) is '.array-5-pt' which I used in the code below:
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
if($('#question{QID}').hasClass('.array-5-pt') {
// Find the checked option for question code Q1
var qc = '{Q1}';
// Check the corresponding option here
$('#answer{SID}X{GID}X{QID}SQ001-A'+qc).prop('checked', true);
}
});
</script>
I inserted this piece of code at the beginning of question.pstpl but it's not working - I'll keep looking into what's wrong. I have attached my test survey and test template to this post if you want to try it out on your end.
A quick update: I found that my original code below works by placing it in template/question.pstpl if the question type is '5 point choice' but does not work when it's an 'array'. It is throwing an "undefined variable" error on the question code. How do I resolve this?