- Posts: 10632
- Thank you received: 3696
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
fill ranking array with answers from previous question
- tpartner
- Away
- LimeSurvey Community Team
Less
More
12 years 3 months ago #70794
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic fill ranking array with answers from previous question
Are Q1 and Q2 on the same page?
Are you using group-by-group mode so you can insert a hidden question?
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 topic has been locked.
- hmoore1024
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
12 years 3 months ago #70796
by hmoore1024
Replied by hmoore1024 on topic fill ranking array with answers from previous question
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.
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 topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10632
- Thank you received: 3696
12 years 3 months ago - 12 years 3 months ago #70815
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic fill ranking array with answers from previous question
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.
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.
Code:
<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: 12 years 3 months ago by tpartner.
The topic has been locked.
- rvas
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 1
11 years 5 months ago #86586
by rvas
Replied by rvas on topic fill ranking array with answers from previous question
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!
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 topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
11 years 2 months ago #90542
by Mazi
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic fill ranking array with answers from previous question
Please attach your survey for testing so we can check the details of the implementation.
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.