Using previous Array question responses to set following Array subquestions

More
5 years 9 months ago #62681 by tpartner
tpartner replied the topic: Using previous Array question responses to set following Array subquestions
Yes, this is always the case. LS needs to generate new group and question IDs because you may already have those IDs in your database from other surveys.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 9 months ago #62684 by MaLu
MaLu replied the topic: Using previous Array question responses to set following Array subquestions
Hi again!

Your help is excellent and highly appreciated. Now I have a slightly different question/problem...

In another question, I'd like to use previous answers to limit subsequent answering options, however, not appearing as a row but as a column. Is that possible as well? Or do you know a workaround for that as well?
Attached you can find a screenshot that might clarify my question…

Thanks a lot!
Marie
Attachments:

Please Log in to join the conversation.

More
5 years 9 months ago #62700 by tpartner
tpartner replied the topic: Using previous Array question responses to set following Array subquestions
Hmm, tricky, I'll have to give that some thought. Can you attach a short sample survey for me to test?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 9 months ago #62712 by MaLu
MaLu replied the topic: Using previous Array question responses to set following Array subquestions
Hi Tony,

I activated the test survey I'm using.

www.panel.statista.com/befragung/admin/a...oup&sid=64137&gid=38

survey ID 64137
Question group ID 38

Is that what you're asking for?
Unfortunately, it's in German. In case of any language barrier, let me know, I’ll try to get an English version…

Salut,
Marie

Please Log in to join the conversation.

More
5 years 9 months ago #62730 by tpartner
tpartner replied the topic: Using previous Array question responses to set following Array subquestions
That survey requires logging in. It would be easier if you could attach an export of a sample survey. That way I wouldn't need to create a survey to test.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 9 months ago #62733 by MaLu
MaLu replied the topic: Using previous Array question responses to set following Array subquestions
Ah ok, got you.
Here's the exported survey sample ...
Attachments:

Please Log in to join the conversation.

More
5 years 9 months ago #62745 by tpartner
tpartner replied the topic: Using previous Array question responses to set following Array subquestions
Okay, add the following script to the source of the multiple-options question (or its help). Replace "MM" with the multiple-options question ID and "AA" with the array question ID (line 7).

The script assigns column-specific classes to the answer cells and answer headers of the array question. Then it loops through all checkboxes in the multiple-options question and if they aren't checked, hides the corresponding column elements in the array question.

There is also a listener on the multiple-options checkboxes so the script can be used to filter the columns of the array dynamically (without hiding the multiple-options question). It was unclear from your description whether or not you wanted to hide the multiple-options question, so I didn't.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Call the column  handling function
		// Params - the IDs of the checkbox question and the array question
		handleCols(MM, AA);
 
		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 listener on the checkboxes to hide or show array columns depending on checkboxes
			$('#question'+qCheckbox+' input.checkbox').click(function(){
				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>

Here is a sample survey with the script in the source of the first question help text in the first group (the multiple-options question help text). You will need to change the question IDs in line 7 of the script to match those in your survey after importing (group and question IDs get changed in the import process). I also put a condition on the array so it only appears if there are checked boxes in the multiple-options question.

File Attachment:

File Name: limesurvey...3996.lss
File Size:47 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:

Please Log in to join the conversation.

More
5 years 9 months ago #62802 by MaLu
MaLu replied the topic: Using previous Array question responses to set following Array subquestions
Hi Tony!

I’m truly sorry for being that imprecise! In the test survey our solution works perfectly, however, allying it to my real survey, where the multiple-options question is already hidden, it doesn’t. I thought it wouldn’t make any difference whether or not the initial question is hidden.

If I unhide the question and actively check any of its boxes the mechanism works. Unfortunately not, if any of the boxes get checked automatically…

I hope you can find some time to help me out yet another time!
Marie

Please Log in to join the conversation.

More
5 years 9 months ago #62825 by tpartner
tpartner replied the topic: Using previous Array question responses to set following Array subquestions
How are you hiding the question?

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 9 months ago #62833 by MaLu
MaLu replied the topic: Using previous Array question responses to set following Array subquestions
I'm using the script that you postet previously.

$(document).ready(function() {

// Call the function
// Params - Q1 ID, Hidden question ID
//Q2 ID herausgenommen
countChecked(1256, 846);

function countChecked(q1ID, qHiddenID) {

// 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)
});

// 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)
});
}

});

</script>

Please Log in to join the conversation.

More
5 years 9 months ago #62842 by tpartner
tpartner replied the topic: Using previous Array question responses to set following Array subquestions
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.

Please Log in to join the conversation.

More
5 years 9 months ago #62853 by MaLu
MaLu replied the topic: Using previous Array question responses to set following Array subquestions
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:

Please Log in to join the conversation.

More
5 years 9 months ago #63148 by MaLu
MaLu replied the topic: Using previous Array question responses to set following Array subquestions
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

Please Log in to join the conversation.

More
5 years 9 months ago #63196 by tpartner
tpartner replied the topic: Using previous Array question responses to set following Array subquestions
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.
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

More
5 years 9 months ago #63198 by tpartner
tpartner replied the topic: Using previous Array question responses to set following Array subquestions
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.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.