- Posts: 10109
- Thank you received: 3595
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Fill dropdown list options with previous dropdown list answers
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
3 years 8 months ago #204418
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 dropdown list options with previous dropdown list answers
Can you activate a small test survey and give a link here so we can see what is affecting that?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- FaLifeTime
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 0
3 years 8 months ago #204419
by FaLifeTime
Replied by FaLifeTime on topic Fill dropdown list options with previous dropdown list answers
Sure. Here it goes:
encuestas.ead.unlp.edu.ar/index.php/827697
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
3 years 8 months ago #204422
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 dropdown list options with previous dropdown list answers
Can you disable AJAX in the survey theme options?
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: FaLifeTime
The topic has been locked.
- FaLifeTime
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 0
3 years 8 months ago #204428
by FaLifeTime
Replied by FaLifeTime on topic Fill dropdown list options with previous dropdown list answers
You are a genius. Thanks a lot. Now is working perfectly.
I have two last question related to the beginning of this post, questions 2) and 3). I'll repeat them just to make it more readable and luckly more clear (sorry if it's redundant). Also I'll share a limesurvey link with the situations and the lss export file.
2)I have a two columns Array(Texts) item (p001) where each option/cell it’s a dropdown list in order to normalize the inputs. There is only one option from the first column (SQ001) that if the user select it ( SQ001 = "No"), the corresponding value from the second column should automatically be an specific value (SQ002 = "No corresponde").
For example: Array(text) p001
Column 1 = SQ001 (dropdown list)
Op1: Yes
Op2: No
Column 2 = SQ002 (dropdown list)
Op1: Compartido
Op2: Personal
Op3: No corresponde
The third option Op3 ("No corresponde") should only automatically appears if Op2 ("No") in column 1(SQ001) is chosen.
I use a script for the dropdown list logic in the Array(texts) columns.
3) In a group/section of questions I have a Multiple choice item (p002) where users have to pick one or more options.
Then, in the same group/section, users have to chose only one option among those were picked in p002. I thought about using a radio list item to solve this situation (p003) using the same logic Joffm suggested before (with an ecuation item). I don't know whether this is possible in the same section of question or should i divide them in two separated groups?
Link of the survey here .
I have two last question related to the beginning of this post, questions 2) and 3). I'll repeat them just to make it more readable and luckly more clear (sorry if it's redundant). Also I'll share a limesurvey link with the situations and the lss export file.
2)I have a two columns Array(Texts) item (p001) where each option/cell it’s a dropdown list in order to normalize the inputs. There is only one option from the first column (SQ001) that if the user select it ( SQ001 = "No"), the corresponding value from the second column should automatically be an specific value (SQ002 = "No corresponde").
For example: Array(text) p001
Column 1 = SQ001 (dropdown list)
Op1: Yes
Op2: No
Column 2 = SQ002 (dropdown list)
Op1: Compartido
Op2: Personal
Op3: No corresponde
The third option Op3 ("No corresponde") should only automatically appears if Op2 ("No") in column 1(SQ001) is chosen.
I use a script for the dropdown list logic in the Array(texts) columns.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var qID = {QID}; // Define the select element (dropdown) var select1 = '<select class="inserted-select form-control list-question-select">\ <option value="">-- Elija por favor --</option>\ <option value="si">Sí</option>\ <option value="no">No</option>\ </select>'; // Hide the text inputs $('#question'+qID+' .answer_cell_SQ001 input[type="text"]').hide(); // Insert the select elements $('#question'+qID+' .answer_cell_SQ001').append(select1); // Initially select an option if the question has already been answered $('#question'+qID+' .answer_cell_SQ001 input[type="text"]').each(function(i){ if($(this).val()) { $(this).closest('td').find('.inserted-select').val($(this).val()); } }); // Listener on the dropdowns - insert selected values into hidden text input $('.inserted-select').change(function() { $(this).closest('td').find('input[type="text"]').val($(this).val()); }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); }); $(document).ready(function() { var qID = {QID}; // Define the select element (dropdown) var select1 = '<select class="inserted-select form-control list-question-select">\ <option value="">-- Elija por favor --</option>\ <option value="personal">Personal</option>\ <option value="compartido">Compartido</option>\ <option value="nocorresponde">No corresponde</option>\ </select>'; // Hide the text inputs $('#question'+qID+' .answer_cell_SQ002 input[type="text"]').hide(); // Insert the select elements $('#question'+qID+' .answer_cell_SQ002').append(select1); // Initially select an option if the question has already been answered $('#question'+qID+' .answer_cell_SQ002 input[type="text"]').each(function(i){ if($(this).val()) { $(this).closest('td').find('.inserted-select').val($(this).val()); } }); // Listener on the dropdowns - insert selected values into hidden text input $('.inserted-select').change(function() { $(this).closest('td').find('input[type="text"]').val($(this).val()); }); // Clean-up styles $('select.inserted-select', thisQuestion).css({ 'max-width': '100%' }); $('input:text', thisQuestion).css({ 'position': 'absolute', 'left': '-9999em' }); }); </script>
3) In a group/section of questions I have a Multiple choice item (p002) where users have to pick one or more options.
Then, in the same group/section, users have to chose only one option among those were picked in p002. I thought about using a radio list item to solve this situation (p003) using the same logic Joffm suggested before (with an ecuation item). I don't know whether this is possible in the same section of question or should i divide them in two separated groups?
Link of the survey here .
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
3 years 8 months ago #204436
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 dropdown list options with previous dropdown list answers
2) You have many redundancies in your script so it can be shortened considerably. To force the column-2 answer to "nocorresponde" if column-1 is "no", add the snippet under the comment "Listener on column-1 dropdowns handle the column-2 answer".
3) Use the array filter feature - manual.limesurvey.org/Question_type_-_Li...r_.28array_filter.29
Sample survey attached:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var qID = {QID}; // Define the select elements (dropdown) var select1 = '<select class="inserted-select form-control list-question-select">\ <option value="">-- Elija por favor --</option>\ <option value="si">Sí</option>\ <option value="no">No</option>\ </select>'; var select2 = '<select class="inserted-select form-control list-question-select">\ <option value="">-- Elija por favor --</option>\ <option value="personal">Personal</option>\ <option value="compartido">Compartido</option>\ <option value="nocorresponde">No corresponde</option>\ </select>'; // Hide the text inputs $('#question'+qID+' .answer_cell_SQ001 input[type="text"], #question'+qID+' .answer_cell_SQ002 input[type="text"]').hide(); // Insert the select elements $('#question'+qID+' .answer_cell_SQ001').append(select1); $('#question'+qID+' .answer_cell_SQ002').append(select2); // Initially select an option if the question has already been answered $('#question'+qID+' .answer_cell_SQ001 input[type="text"], #question'+qID+' .answer_cell_SQ002 input[type="text"]').each(function(i){ if($(this).val()) { $(this).closest('td').find('.inserted-select').val($(this).val()); } }); // Listener on the dropdowns to load selected values into the hidden text inputs $('#question'+qID+' .inserted-select').change(function() { $(this).closest('td').find('input[type="text"]').val($(this).val()); }); // Listener on column-1 dropdowns handle the column-2 answer $('#question'+qID+' .answer_cell_SQ001 .inserted-select').change(function() { if($(this).val() == 'no') { var thisRow=$(this).closest('tr'); $('.answer_cell_SQ002 .inserted-select', thisRow).val('nocorresponde').trigger('change'); } }); // Clean-up styles $('#question'+qID+' select.inserted-select').css({ 'max-width': '100%' }); $('#question'+qID+' input:text').css({ 'position': 'absolute', 'left': '-9999em' }); }); </script>
3) Use the array filter feature - manual.limesurvey.org/Question_type_-_Li...r_.28array_filter.29
Sample survey attached:
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: FaLifeTime
The topic has been locked.
- FaLifeTime
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 0
3 years 8 months ago #204445
by FaLifeTime
Replied by FaLifeTime on topic Fill dropdown list options with previous dropdown list answers
Works perfectly. Thanks. I'm getting this error when I try to recreate what Joffm told me: "The usual procedure by inserting a hidden question of type multiple, setting the necessary options by an equation and using this"
In my ecuation i try to insert 1000 rows like this
{m104_A1=if(p072=="A1" or p094=="A1" or p095=="A1" or p096=="A1" or p097=="A1" or p098=="A1" or p099=="A1" or p100=="A1,Y","")}
I got the following error:
I imagine that its been caused by the lenght of the text. Do know how can i fix this?
Thanks for all!
4aLifeTime
In my ecuation i try to insert 1000 rows like this
{m104_A1=if(p072=="A1" or p094=="A1" or p095=="A1" or p096=="A1" or p097=="A1" or p098=="A1" or p099=="A1" or p100=="A1,Y","")}
I got the following error:
I imagine that its been caused by the lenght of the text. Do know how can i fix this?
Thanks for all!
4aLifeTime
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
3 years 8 months ago #204450
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 dropdown list options with previous dropdown list answers
You cannot, the error message says it all. You will have to come up with a workaround like using several questions.
Even if you did get that to work, I suspect it would be incredibly slow with Expression Manager processing that many OR statements.
Even if you did get that to work, I suspect it would be incredibly slow with Expression Manager processing that many OR statements.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- FaLifeTime
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 0
3 years 8 months ago #204451
by FaLifeTime
Replied by FaLifeTime on topic Fill dropdown list options with previous dropdown list answers
I imagined that. Do you know whether there is an old post where I can have a clue how to fill a radio list or a dropdown list from others previous dropdown lists answered (in a previuos section of questions)?
So far, thanks for all the time u spent with my questions. I have solved a lot.
4aLifeTime
So far, thanks for all the time u spent with my questions. I have solved a lot.
4aLifeTime
The topic has been locked.