Welcome, Guest
Username: Password:

TOPIC: fill ranking array with answers from previous question

fill ranking array with answers from previous question 4 years 7 months ago #66034

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5914
  • Thank you received: 357
  • Karma: 262
You could either switch to group-by-group or all-in-one survey mode or add another line of JS code if you are using question-by-question format. That code could click the "next" button so the hidden question would be skipped automatically.

See docs.limesurvey.org/Workarounds%3A+Manip...ing_the_welcome_page for example.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

fill ranking array with answers from previous question 4 years 7 months ago #66057

  • stigchelg
  • stigchelg's Avatar
  • Offline
  • Junior Lime
  • Posts: 26
  • Karma: 0
Hmm, ok I tried this and it does work as describe only that page flash is a bit strange even with a fake loading text. Surely there is a more elegant solution.

This may be the stupid question of the week, but why can't I just route past these questions? When question 3 has been answers, skip straight to question 5.

Oh and even though the construct works now, I'm still having trouble. I can only get it to prefill from a question on the same page. When I change it with the ID of the question on the previous page and add ", 1" to the small script, It doesn't work.
The administrator has disabled public write access.

fill ranking array with answers from previous question 4 years 7 months ago #66072

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5914
  • Thank you received: 357
  • Karma: 262
stigchelg wrote:
Oh and even though the construct works now, I'm still having trouble. I can only get it to prefill from a question on the same page. When I change it with the ID of the question on the previous page and add ", 1" to the small script, It doesn't work.
Javascript reads out the information from the source code (DOM objects) of the currently displayed page. Therefore you can only access items which are listed on the same page.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

fill ranking array with answers from previous question 4 years 7 months ago #66094

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5761
  • Thank you received: 1250
  • Karma: 512
This should help get rid of the flash.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		$('body').hide();
		$('form#limesurvey').submit(); 
	});
 
</script>

But if you use this workaround and are allowing the "Previous" button, you may need to add a script to the following page so that if the "Previous" button is clicked the hidden question group is also skipped.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

fill ranking array with answers from previous question 4 years 7 months ago #66299

  • stigchelg
  • stigchelg's Avatar
  • Offline
  • Junior Lime
  • Posts: 26
  • Karma: 0
Ok, after a weekend of testing and cursing. I am satisfied with the result. I have moved on to the next project in line which is a multiple numerical with slider lay-out. How can I filter this type of question? It also does not have the filter array option.

BTW Tpartner. Are you in anyway affiliated with Limesurvey?
The administrator has disabled public write access.

fill ranking array with answers from previous question 4 years 7 months ago #66357

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5761
  • Thank you received: 1250
  • Karma: 512
...which is a multiple numerical with slider lay-out. How can I filter this type of question?
I think I already answered that - www.limesurvey.org/forum/can-i-do-this-w...art=30&lang=en#59877

I'm only affiliated as a volunteer on the development team.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

fill ranking array with answers from previous question 4 years 6 months ago #66627

  • stigchelg
  • stigchelg's Avatar
  • Offline
  • Junior Lime
  • Posts: 26
  • Karma: 0
I've tried this workaround, but I don't see how it pertains to my problem. I may be missing the point entirely, but how does this add a filter array to a multiple numerical question?

I'll just ago ahead and make a donation then. If it doesn't benefit your directly, it'll do some good somewhere in the development I guess :).
The administrator has disabled public write access.

fill ranking array with answers from previous question 4 years 6 months ago #66643

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5761
  • Thank you received: 1250
  • Karma: 512
That script is to filter a multiple numeric question with a hidden multiple options question.

Thanks for the donation, it will go towards server costs, etc. to keep the software and support free.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

fill ranking array with answers from previous question 4 years 6 months ago #66656

  • stigchelg
  • stigchelg's Avatar
  • Offline
  • Junior Lime
  • Posts: 26
  • Karma: 0
Rightio. And I just copy that script you linked to into the multiple numeric and fill in the appropriate questions?

Cause I did that and it's not filtering. I wonder what I keep doing wrong.
The administrator has disabled public write access.

fill ranking array with answers from previous question 4 years 4 months ago #70791

  • hmoore1024
  • hmoore1024's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
I've read through all of this and several other threads on the topic and I'm still a little confused. I am absolutely not a js person in any way, but I can copy and paste pretty well. ;)

My problem is a little different from what I'm seeing here - I'm trying to pull answers that were selected in one array into a second array.

So Q1 is a list of options with 3 possible answers.
Q2 should only display options that received answer "a" or answer "b" and filter out any options that received answer "c".

I think I understand the basic logistics involved here, I just am not sure if pulling to a ranked array or pulling to a labelled array makes any difference and how to differentiate the answers A/B/C for each of the options using a multiple choice question.

To further complicate things we just upgraded from 1.85 or so 1.90 and it's a learning experience!
The administrator has disabled public write access.

fill ranking array with answers from previous question 4 years 4 months ago #70794

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5761
  • Thank you received: 1250
  • Karma: 512
Are Q1 and Q2 on the same page?

Are you using group-by-group mode so you can insert a hidden question?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

fill ranking array with answers from previous question 4 years 4 months ago #70796

  • hmoore1024
  • hmoore1024's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 2
  • Karma: 0
I have them on different pages, assuming that the answers for Q1 would need to "submit" before being able to be read for Q2.

They're presented group by group and read through the instructions for hidden questions - I just wasn't sure how that would work for an array where I'm looking to pull options with specific responses forward.
The administrator has disabled public write access.

fill ranking array with answers from previous question 4 years 4 months ago #70815

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5761
  • Thank you received: 1250
  • Karma: 512
Okay, in that case you can add a hidden multiple-options question (qHidden) to control the display of Q2 with an array filter. A script can auto-check the corresponding option in qHidden if an answer in columns 1 or 2 of Q1 are clicked.

1) Set up your survey to use JavaScript.

2) Add a multiple-options question (qHidden) to the group containing Q1. Give it the same sub-questions and codes as Q1.

3) Add an array filter to Q2 based on qHidden.

4) Add the following script to the source of Q1. Replace "11" with the Q1 question ID and "HH" with the qHidden question ID.

The script:
- Hides the multiple-options question (qHidden)
- Puts a listener on the array cells of Q1.
- If a cell in column 1 or 2 of Q1 is clicked, the corresponding option in qHidden is checked.
- If a cell in any other column of Q1 is clicked, the corresponding option in qHidden is unchecked.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() { 
 
		// Call the autoClick function
		// Params - Array ID, Hidden question ID, Column of array that auto-checks the hidden question
		autoClick(11, HH, 1);
		autoClick(11, HH, 2);
 
		function autoClick(qArrayID, qHiddenID, column) {
 
			// 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];
			} 
 
			// Add some column-specific classes
			$('#question'+qArrayID+' table.question tr').each(function(i, el){
				$('> *', this).each(function(i, el){
					$(el).addClass('col-'+i);
				});
			});
 
			// Add a class to answers that are to auto-check the hidden question
			$('#question'+qArrayID+' .col-'+column).addClass('autoClick');
 
			// A listener on the Q1 radio buttons 
			$('#question'+qArrayID+' table.question tbody td').click(function () {
				var rowID = $(this).parents('tbody:eq(0)').attr('id');
				var tmp2 = rowID.split('X'+qArrayID);
				var answerCode = tmp2[1];
				// This cell checks the corresponding option it qHidden
				if($(this).hasClass('autoClick')) {
					$('#answer'+sID+'X'+gID+'X'+qHiddenID+answerCode).attr('checked', true);
				}
				// This cell unchecks the corresponding option it qHidden
				else {
					$('#answer'+sID+'X'+gID+'X'+qHiddenID+answerCode).attr('checked', false);
				}
			});
		}
 
	});
 
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 4 years 4 months ago by tpartner.
The administrator has disabled public write access.

fill ranking array with answers from previous question 3 years 6 months ago #86586

  • rvas
  • rvas's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 7
  • Thank you received: 1
  • Karma: 1
Hi all! I am using LimeSuvey 2+ and I have a problem trying to do something similar.

I want to do the same as described earlier but in the same page. I managed to do it properly in two different pages using the code provided above with a slight modification
(I replaced the line 'var rowID = $(this).parents('tbody:eq(0)').attr('id');' with 'var rowID = $(this).parents('tr:eq(0)').attr('id');')

Unfortunately while I have added an array filter to the Q2 array based on qHidden, it cannot capture the checkboxes of qHidden if they are triggered by javascript. Is there a workaround to that?

Many thanks in advance!
The administrator has disabled public write access.

fill ranking array with answers from previous question 3 years 3 months ago #90542

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5914
  • Thank you received: 357
  • Karma: 262
Please attach your survey for testing so we can check the details of the implementation.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.218 seconds