Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Array effecting another array

Array effecting another array 1 year 7 months ago #91936

  • Ugnius
  • Ugnius's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
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
yesno
thing1OO
Thing2OO



then there would be another array
highlow
thing3OO
Thing4OO

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...

Is there anyone willing to help me ?
The administrator has disabled public write access.

Re: Array effecting another array 1 year 7 months ago #91966

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4141
  • Thank you received: 768
  • Karma: 349
You can use JavaScript to do this but the details would depend on the question types. Can you attach a sample survey with those two questions?
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.

Re: Array effecting another array 1 year 7 months ago #91981

  • Ugnius
  • Ugnius's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
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 :)
Attachments:
The administrator has disabled public write access.

Re: Array effecting another array 1 year 7 months ago #91986

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4141
  • Thank you received: 768
  • Karma: 349
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Array effecting another array 1 year 7 months ago #91989

  • Ugnius
  • Ugnius's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
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.
The administrator has disabled public write access.

Re: Array effecting another array 1 year 7 months ago #91998

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4141
  • Thank you received: 768
  • Karma: 349
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
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		// Identify the questions
		var 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 rows
		function 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 colours
			var 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 q2
			if($('.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.

File Attachment:

File Name: limesurvey_survey_241336_TP.lss
File Size: 27 KB
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.

Re: Array effecting another array 1 year 7 months ago #92071

  • Ugnius
  • Ugnius's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
It looks great and I'm really thankful, but of course there is a problem and I hope it is the last one.

I need this survey to be strictly to be in Lithuanian language without English language option.

As far as I can see there is no way to change the base language and I am not able to remake this survey myself with new base language.

Could you help me out on this and make another file that I could download with Lithuanian base language ?
The administrator has disabled public write access.

Re: Array effecting another array 1 year 6 months ago #92082

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4141
  • Thank you received: 768
  • Karma: 349
The code is fully portable and not affected by language.

You can copy and paste the script from the source of question code "F" to an array in your Lithuanian survey.
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.

Re: Array effecting another array 7 months 2 weeks ago #103604

  • LloydW
  • LloydW's Avatar
  • OFFLINE
  • Gold Donor
  • Posts: 32
  • Thank you received: 1
  • Karma: 0
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?
The administrator has disabled public write access.

Re: Array effecting another array 7 months 2 weeks ago #103606

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4141
  • Thank you received: 768
  • Karma: 349
Not tested, but try changing this:
var q2 = $(q1).nextAll('.array-flexible-row:eq(0)');

To this:
var q2 = $(q1).nextAll('.array-flexible-row:eq(0), .array-flexible-row:eq(1), .array-flexible-row:eq(2), .array-flexible-row:eq(3)');


That will include the next 4 array questions in the "$(q2)" object.

Oh, and you can remove this - it's not required.:
var q2ID = $(q2).attr('id').split('question')[1];
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.
The following user(s) said Thank You: LloydW
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.159 seconds
Donation Image