Welcome, Guest
Username: Password: Remember me

TOPIC: fill ranking array with answers from previous question

Re: fill ranking array with answers from previous question 2 years 8 months ago #70794

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4117
  • Thank you received: 760
  • Karma: 346
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.

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: fill ranking array with answers from previous question 2 years 8 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.

Re: fill ranking array with answers from previous question 2 years 8 months ago #70815

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4117
  • Thank you received: 760
  • Karma: 346
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 2 years 8 months ago by tpartner.
The administrator has disabled public write access.

Re: fill ranking array with answers from previous question 1 year 10 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.

Re: fill ranking array with answers from previous question 1 year 7 months ago #90542

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 293
  • Karma: 248
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.158 seconds
Donation Image