Hello, I am a student and I am doing a year project which requires doing an survey. I decided that I want the surwey to be online and realised that I need some more powerful features which I found in Lime Survey, but since I am a begginer I came across some problems and now I am here asking for help...
My englsih language is also not the greatest, but I hope you will be able to understand my problem.
I'm trying to create a survey which would start with array like this
yes
no
thing1
O
O
Thing2
O
O
then there would be another array
high
low
thing3
O
O
Thing4
O
O
And I want to make that if in the first array you choose answer "no" next to "thing1" , then you won't need to answer "thing3" in the seccond array and it would simply disappear.
This seemed obvious to somehow make it in question conditions, but after googling for a while I red that Lime Survey just simply doesn't support subquestion conditions.
Is there a way that I could still make this ? It seems like it would be possible with array filters and I tried downloading some examples from wiki but I just can't put my head around it...
I made this sample survey with actual questions and answers in it to make it clear what I am after.
In the first array person chooses the amount of days per week that he spends on the certain things and in the second array he would choose the amount of hours per day on the same certain things.
But you know, if in the first array person answers that he doesn't spend any days per week on for example watching TV, than it would be less frustrating if in the second array sub question about hours per day watching TV would disappear.
And also another questions pops up asking why the person isn't watching TV which I already made in this sample survey.
I hope you were able to understand me and since I explained exactly what kind of information I'm trying to get from people and you or anybody else have a simpler idea on how to get this information than making two arrays like I did then please show me
I understand now but maybe a better behaviour would be to only show rows in q2 if days are selected instead of hiding them. What do you you think?
Also, if you want to make q2 mandatory, can we add an "N/A" option that we can check if the row is hidden? (we can hide the "N/A" column from respondents)
Cheers,
Tony Partner Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
I personally like to see straight away how much questions will there be in a survey and that is why I want it to look the way I explained it before and I'm not sure which behaviour would be better. probably stick to the one, that is less time consuming to make.
And yes add an "N/A" option if it is what you need.
Okay, here's a script that when placed in the source of the first array:
- Identifies the two arrays (we'll call them q1 and q2)
- Hides the "N/A" column of q2
- When a radio in column 1 of q1 is clicked, the corresponding row in q2 is hidden and its "N/A" option is selected
- When any other radio in q1 is clicked, the corresponding row in q2 is shown and its "N/A" option is de-selected
Code:
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){// Identify the questionsvar q1ID ='{QID}';var q1 = $('#question'+q1ID+'');var q2 = $(q1).nextAll('.array-flexible-row:eq(0)');var q2ID = $(q2).attr('id').split('question')[1];// Add some classes
$('input.radio', q1).each(function(i){if($('input.radio', $(this).closest('tr')).index($(this))==0){
$(this).addClass('exclusive');}});// Hide the "N/A" column of q2
$('thead th:last', q2).hide();
$('tr[id^="javatbd"]', q2).each(function(i){
$('td:last', this).hide();});// Initially Hide/Show the appropriate q2 rows
$('input.radio:checked', q1).each(function(i){
handleRows($(this));});// Click events on Q1 radios
$('input.radio', q1).click(function(){
handleRows($(this));});
$('input.radio', q1).closest('td').click(function(){
handleRows($('input.radio', this));});// A function to hide/show the appropriate q2 rowsfunction handleRows(el){var rowIndex = $('tr', $(el).closest('tbody')).index($(el).closest('tr'));if($(el).hasClass('exclusive')){// Check the "N/A" in the q2 row
$('tr[id^="javatbd"]:eq('+rowIndex+') input.radio:last', q2).attr('checked',true)// Hide the q2 row
$('tr[id^="javatbd"]:eq('+rowIndex+')', q2).hide();}else{// Un-check the "N/A" in the q2 row
$('tr[id^="javatbd"]:eq('+rowIndex+') input.radio:last', q2).attr('checked',false)// Show the q2 row
$('tr[id^="javatbd"]:eq('+rowIndex+')', q2).show();}// Now, fix up the q2 row background coloursvar q2RowIndex =0;
$('tr[id^="javatbd"]:visible', q2).each(function(i, el){
q2RowIndex ++;
$(el).removeClass('array1, array2');if(q2RowIndex %2==0){
$(el).addClass('array1');}else{
$(el).addClass('array2');}});// Hide/show q2if($('.radio.exclusive:checked', q1).length == $('.radio.exclusive', q1).length){
$(q2).hide();}else{
$(q2).show();}}});</script>
Here's the survey back with the script in the first question of the first group.
I've successfully implemented this and adapted for the question styles I have. But I also have q3, q4 & q5 which like q2 depended on the check box of q1. How would I make this solution apply to the extra arrays - is there a simple way using a for() function?