Welcome, Guest
Username: Password: Remember me

TOPIC: Using previous Array question responses to set following Array subquestions

Re: Using previous Array question responses to set following Array subquestions 3 years 1 month ago #62842

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4115
  • Thank you received: 760
  • Karma: 346
Okay, now I'm confused about the total scope of the workaround. I don't see my latest code in that script.
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: Using previous Array question responses to set following Array subquestions 3 years 1 month ago #62853

  • MaLu
  • MaLu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • Karma: 0
Oh, ok. Well, what I'm trying to do is to limit the size of some survey questions in rows and columns. I attached a screenshot what it should look like.

Following your previous script, the two multiple-option questions (x and x2) are both hidden (only for the test unhidden) and automatically filled by answering the array questions before them (Q1 respective Q4). For subsequent questions, I then used the filter option inserting x respective x2. So far the survey works perfectly.

In Q5, I’d like to limit both rows and columns. Hiding rows seems fairly easy using the filter again. Inserting your script to limit the columns, it only works, if I actively check or uncheck any box in x. Is it possible to transfer the automatically filled answers to Q5 as well?
I also attached the survey.

Well knowingly that I’m asking quite a lot, I hope you can help me out…

Best,
Marie
Attachments:
The administrator has disabled public write access.

Re: Using previous Array question responses to set following Array subquestions 3 years 1 month ago #63148

  • MaLu
  • MaLu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • Karma: 0
Is there an option to simulate the click in the hidden question so it pretends to be actively clicked?

Appreciate all the help and comments I can get!
Marie
The administrator has disabled public write access.

Re: Using previous Array question responses to set following Array subquestions 3 years 1 month ago #63196

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4115
  • Thank you received: 760
  • Karma: 346
Sorry Marie for the delay.

Remove all scripts in "x", "x2" and "Q5". Insert the following script in the source of "x". This script is an aggregation of the 3 that you were using with the countChecked() function modified to handle the hide/show columns part.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() { 
 
		// Call the show/hide rows function
		// Params - Array ID, Hidden question ID, Column question
		countChecked(1256, 846, 852);
		countChecked(1289, 1295);
 
		// Call the initialisation of the hide/show columns function
		// Params - the IDs of the checkbox question and the array question
		handleCols(846, 852);
 
		function countChecked(q1ID, qHiddenID, qColumns) {
 
			// Hide the hidden question
			//$('#question'+qHiddenID+'').hide();
 
			// Find the survey and group IDs
			if($('input#fieldnames').length != 0) {
				var fieldNames = $('input#fieldnames').attr('value');
				var tmp = fieldNames.split('X');
				var sID = tmp[0];
				var gID = tmp[1];
			}
 
			// A listener on the 1st column of Q1 radio buttons 
			$('#question'+q1ID+' td.answer_cell_00A1').click(function () { 
 
				// Uncheck the corresponding option in the hidden question
				var rowID = $(this).parents('tbody:eq(0)').attr('id');
				var tmp2 = rowID.split('X'+q1ID);
				var answerCode = tmp2[1];
				$('#answer'+sID+'X'+gID+'X'+qHiddenID+answerCode).attr('checked', false);
 
				// Fire the conditions function to hide the corresponding row in Q2
				var hiddenInputValue = $('#answer'+sID+'X'+gID+'X'+qHiddenID+answerCode).attr('value');
				var hiddenInputName = $('#answer'+sID+'X'+gID+'X'+qHiddenID+answerCode).attr('name');
				var hiddenInputType = $('#answer'+sID+'X'+gID+'X'+qHiddenID+answerCode).attr('type');
				checkconditions(hiddenInputValue, hiddenInputName, hiddenInputType);
				if(qColumns) {
					hideShow(qHiddenID, qColumns);
				}
			});
 
			// A listener on the 2nd and 3rd columns of Q1 radio buttons 
			$('#question'+q1ID+' td.answer_cell_00A3, #question'+q1ID+' td.answer_cell_00A5').click(function () { 
 
				// Check the corresponding option in the hidden question
				var rowID = $(this).parents('tbody:eq(0)').attr('id');
				var tmp2 = rowID.split('X'+q1ID);
				var answerCode = tmp2[1];
				$('#answer'+sID+'X'+gID+'X'+qHiddenID+answerCode).attr('checked', true);
 
				// Fire the conditions function to show the corresponding row in Q2
				var hiddenInputValue = $('#answer'+sID+'X'+gID+'X'+qHiddenID+answerCode).attr('value');
				var hiddenInputName = $('#answer'+sID+'X'+gID+'X'+qHiddenID+answerCode).attr('name');
				var hiddenInputType = $('#answer'+sID+'X'+gID+'X'+qHiddenID+answerCode).attr('type');
				checkconditions(hiddenInputValue, hiddenInputName, hiddenInputType);
				if(qColumns) {
					hideShow(qHiddenID, qColumns);
				}
			});
		}
 
		// The initialisation of the hide/show columns function
		function handleCols(qCheckbox, qArray) {
 
			// Assign column-specific classes to answer cells of the "column" question
			$('#question'+qArray+' table.question thead th').each(function(i){
				$(this).addClass('ansCol'+i+'');
			});
			$('#question'+qArray+' table.question tbody').each(function(i){
				$('td', this).each(function(i){
					$(this).addClass('ansCol'+i+'');
				});
			});
 
			// Initially hide or show array columns depending on checkboxes
			hideShow(qCheckbox, qArray);
		}
 
		// A function to hide or show columns depending on checkboxes in a multi-opt question
		function hideShow(qCheckbox, qArray) {
 
			// Loop through all multi-opt checkboxes
			$('#question'+qCheckbox+' input.checkbox').each(function(i){
				if($(this).attr('checked') == true) {
					$('#question'+qArray+' .ansCol'+i+'').show();
				}
				else {
					$('#question'+qArray+' .ansCol'+i+'').hide();
					$('#question'+qArray+' .ansCol'+i+' input[type="checkbox"]').attr('checked', false);
				}
			});
		}
 
	});
 
</script>
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: DenisChenu

Re: Using previous Array question responses to set following Array subquestions 3 years 1 month ago #63198

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4115
  • Thank you received: 760
  • Karma: 346
Oh, and check those IDs in rows 7, 8 and 12. I'm pretty sure those are the IDs from your survey but you may need to change them if you have exported/imported the 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: Using previous Array question responses to set following Array subquestions 3 years 1 month ago #63217

  • MaLu
  • MaLu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • Karma: 0
Brilliant! That works perfectly now, just the way I wanted it to!!

And here’s my last question for now: Is it possible to show the questions one by one without paralysing the mechanism?

Thank you so much for your patient support! Hope I wasn’t bothering you too much…

Cheers,
Marie
The administrator has disabled public write access.

Re: Using previous Array question responses to set following Array subquestions 3 years 1 month ago #63225

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4115
  • Thank you received: 760
  • Karma: 346
If you mean place the questions on different pages, no. The script can only manipulate question on the same page.
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: MaLu

Re: Using previous Array question responses to set following Array subquestions 2 years 10 months ago #65993

  • Maximilien
  • Maximilien's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 12
  • Karma: 0
Hi,

I had pretty much the same problem that the initial question described. I used the script you provided Tony, and I really thank you for all your work.

I have a little issue though, and I don't know how to fix it.
It appears that the listener
$('#question'+q1ID+' td.answer_cell_002').click(function () {

is listening on the cell of the array... Not on the checkboxes. My problem is that it works fine if the user (as most users do) clicks on the cell, but it fails if he clicks on the checkbox itself!
Quite trick. It's not too difficult to listen on a cell (all cells are identified by the same class "answer_cell_00xxx") but it looks more difficult to listen on the checkboxes of a column (they are identified by ids and names that differs from one to the other).

Am I missing something ?
Any idea to get this working ? (I do have users that click right on the checkbox sadly)

Thanks in advance,
Maximilien
The administrator has disabled public write access.

Re: Using previous Array question responses to set following Array subquestions 2 years 10 months ago #65996

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6252
  • Thank you received: 799
  • Karma: 239
Maybe something like that:
$('#question'+q1ID+' td.answer_cell_002, #question'+q1ID+' td.answer_cell_002 input:checkbox').click(function () {

The jquery api : api.jquery.com/
The administrator has disabled public write access.
The following user(s) said Thank You: Maximilien

Re: Using previous Array question responses to set following Array subquestions 2 years 10 months ago #66000

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4115
  • Thank you received: 760
  • Karma: 346
...is listening on the cell of the array... Not on the checkboxes.
This workaround is for array questions with radio buttons. What question type are you using?
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.
Last Edit: 2 years 10 months ago by tpartner.
The administrator has disabled public write access.
The following user(s) said Thank You: Maximilien
Moderators: ITEd
Time to create page: 0.225 seconds
Donation Image