Welcome, Guest
Username: Password: Remember me

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

Using previous Array question responses to set following Array subquestions 3 years 7 months ago #58002

  • StuTheQ
  • StuTheQ's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
Hello !

From reading the documentation and some relevant posts on the forum (in particular Post#56563 from Mazi), I don’t think this is possible but perhaps somebody can suggest a workaround? (I’m using LimeSurvey 1.90+)

Here is my example:

Q1 (3-point) Array: 1=“N/A”, 2 =”Important”, 3=”Priority”

‘n’ subquestions (“Language skills” Ex. Spelling names, finding out basic information, making offers, giving directions etc.)

Q2 (5-point) Array: 1=”I can’t” ... 5=”I can very well”

Identical subquestions to Q1

I wanted to use the ‘Condition OR’ function to dictate which subquestions from Q1 reappear in Q2.

Ex. Only show Q2 SQ001 “Spelling names” if Q1 SQ001 “Spelling names” = “Important” OR “Priority”

However, according to Mazi’s post, conditions can only be applied to whole questions (and not subquestions).

I know that if I replace the Q1 Array with a Multiple Options question (Ex. Please indicate which language skill is “Priority”) and then use the reponses obtained to set the Array Filter for the Q2 Array, I can get something that works well. In this case, though, I lose the nuance between “Important” and “Priority”... :(

Tony Partner’s Post#55940 (Re: Piping from Array to List question) looks useful and perhaps his suggestion could be adapted to my situation?

(unfortunately my programming skills are very limited (a little HTML that I’ve learnt since becoming a Fresh Lemon!) so any approach involving JavaScript (Ex. hidden questions) would require simple, step-by-step instructions from the very kind and patient forum member... sorry! :blush: )

Any suggestions? (or will I have to be less ambitious with my questions?! ;) )

As always, thank you all in advance!

Regards,

StuTheQ
The administrator has disabled public write access.

Re: Using previous Array question responses to set following Array subquestions 3 years 7 months ago #58009

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4256
  • Thank you received: 801
  • Karma: 367
Stu, are the two questions on different pages?

Can you attach exported copies of the 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: Using previous Array question responses to set following Array subquestions 3 years 7 months ago #58035

  • StuTheQ
  • StuTheQ's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
Hello Tony!

Thank you for replying so quickly!

The two questions are not on different pages. At the moment, they're on the same page, in the same group (but I'm not sure how that could be an issue as, from what I understand, conditions work between groups?)

Regarding sending you exported copies of the questions... er, once again I'm not sure how to do that :blush: (I'm also using LimeService so I think that makes things a little more complicated, too). In addition (and please don't think me rude!) I can't see the point? It seems that Q(n) Array responses cannot normally be used in conditions to set Q(n+1) Array subquestions (cf the documentation and Mazi's post#56563).

If you try to do this after setting up Q1 Array (see Screenshot 1), in the Q2 conditions Designer box you see that the condition will apply to the whole question and not the individual subquestion (see Screenshot 2).

However, if you replace your Q1 Array with a Multiple Options (see Screenshot 3) and then set up your Q2 Array with Q1 responses in the Array filter input, then, of course, you get something that works (see Screenshot 4). This is fine, but you lose the nuance of "Important" versus "Priority". :(

I just wondered if there was somehow a way of using Q(n) Array responses to set the Q(n+1) Array subquestions (as I wrote, I saw you suggest something for a similar issue (Post#55940 Re. Piping from Array to List question) but it required implementing a "hidden question" with JavaScript. I don't know if such an approach would work for me but as I said (and as you'll have too quickly gathered!! :blush: ) my programming skills are very limited (although I try to learn quickly!)).

I don't want to waste your time with this (my survey is not going to change the world!) so no problem if there's no straightforward solution.

Thanks once again for your time and patience, Tony!

Regards,

StuTheQ
Attachments:
The administrator has disabled public write access.

Re: Using previous Array question responses to set following Array subquestions 3 years 7 months ago #58056

  • StuTheQ
  • StuTheQ's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
Hi again Tony,

I've been reading some more of your inputs regarding topics which are similar to mine (and in particular, the topic "Filtering some answers from an array" from about 4 weeks ago).

If I understand correctly it seems that it would be necessary to set up a hidden checkbox between Q1 Array and Q2 Array.

JavaScript could then be used to check the boxes in this checkbox according to the responses in Q1 Array (Ex. If answer in Q1 Array SQ001 = "Important" OR "Priority" then check box).

The checkbox responses would then act as the input for the Array Filter of Q2 Array. Thus, the Q1 Array responses would dictate which subquestions appear in Q2 Array, which is what I'm trying to do.

Am I on the right track?

The only problem (and it's a biggy!! :laugh: )is that I don't know how to write or implement the JavaScript code required. I looked at what you wrote but I don't think a simple "Copy and Paste" would work, as the code you wrote is for a specific case (similar in theme, but not identical in type, to mine) and I wouldn't know how to modify it.

Please don't think that I'm chasing you up - I'm just trying to show that I'm not totally hopeless!! :laugh: ;)

Regards,

StuTheQ
The administrator has disabled public write access.

Re: Using previous Array question responses to set following Array subquestions 3 years 7 months ago #58058

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4256
  • Thank you received: 801
  • Karma: 367
Hi Stu,

I was half way through writing this up when you last replied and, yes, you are on the right track.

I asked about pages because a workaround to achieve your behaviour will require JavaScript and that script will vary depending on question placement. The only reason I requested sample questions is because it saves me time - I don't have to create (sometimes very complex) questions to test a solution.

Okay, let's move on to the fun bit. As stated, this will require a little JavaScript but don't worry, I'll be gentle :) .

1) Set up your survey to use JavaScript.

2) Create your Q1 and Q2 arrays with identical subquestion codes.

3) Create a multiple-options question with identical subquestion codes and place it between Q1 and Q2 (call it qHidden - we'll hide it with JavaScript later).

4) Add conditions to Q2 so it is only shown if any option in qHidden is checked. This simply prevents Q2 appearing with no subquestion rows.
Untitled-2_2011-03-09.png


5) Add a filter array to Q2 based on qHidden.

6) Add the following script to the source of qHidden or its help text. Replace the following parameters in line 6:
- 11 = your Q1 ID
- 22 = your Q2 ID
- HH = your qHidden ID

The script:
- hides qHidden
- puts listeners on the radios in Q1
- if they are clicked, checks or unchecks the corresponding option in qHidden
- fires the built-in function to show or hide rows in Q2
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		// Call the function
		// Params - Q1 ID, Q2 ID, Hidden question ID
		countChecked(11, 22, HH);
 
		function countChecked(q1ID, q2ID, 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_001').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_002, #question'+q1ID+' td.answer_cell_003').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>
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: 3 years 7 months ago by tpartner.
The administrator has disabled public write access.
The following user(s) said Thank You: StuTheQ

Re: Using previous Array question responses to set following Array subquestions 3 years 7 months ago #58059

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4256
  • Thank you received: 801
  • Karma: 367
I should point out that this script is specific to your needs - if Q1/Column1 is clicked the corresopnding Q2 row is hidden, if Q1/Column2 or Q1/Column3 are clicked the corresopnding Q2 row is shown.

Having said that, it can easily be modified for other column requirements.
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: StuTheQ

Re: Using previous Array question responses to set following Array subquestions 3 years 7 months ago #58062

  • StuTheQ
  • StuTheQ's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
Dear Tony,

Well, what can I say!! Thank you very much!! :cheer:

It looks great - what I'm going to do now is read it all very carefully before trying to implement the JavaScript code.

By the way, I now totally understand why you asked me if the questions were on the same page - I saw that you asked other people the same question and explained that it was because of the JavaScript. As I was just thinking about standard Condition settings (which you can use between pages, question groups etc.), that's why I didn't understand what you meant.

As for the request for sample questions, copies of files etc. I, of course, completely understand and, as I said, can only offer my embarrassed apologies for my inability to provide them! :blush: (I've looked for info about how to make posts on the Forum more efficient (copies of files, links, reference to previous posts etc.) but haven't really found anything - maybe it's just common IT knowledge..??)

Once again, thank you very much for your time, efforts and patience - I really appreciate it!

Best,

StuTheQ
The administrator has disabled public write access.

Re: Using previous Array question responses to set following Array subquestions 3 years 3 months ago #62518

  • MaLu
  • MaLu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • Karma: 0
Dear Tony and Stu,

I just happened to come across the same problematic; I was trying to modify your solution to my specific needs. Unfortunately, that didn't work, most presumably due to my lack of JavaScript- and LimeSurvey-knowledge.

However, as I was testing your script using Stu’s example, it didn't work either. Is there a trick? How to make it work?

Thanks a lot for your time and support,
Marie
The administrator has disabled public write access.

Re: Using previous Array question responses to set following Array subquestions 3 years 3 months ago #62527

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4256
  • Thank you received: 801
  • Karma: 367
Nope, no real trick. The most common error is incorrect question IDs.

Can you paste the complete code you are using as a test and maybe activate that survey so I can check the IDs?
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 3 months ago #62530

  • MaLu
  • MaLu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 35
  • Karma: 0
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {

// Call the function
// Params - Q1 ID, Q2 ID, Hidden question ID
countChecked(714, 756, 761);

function countChecked(q1ID, q2ID, 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_001').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_002', '#question'+q1ID+'td.answer_cell_003').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>
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.157 seconds
Donation Image