- Posts: 27
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Dropdown in Multiple short text
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
12 years 4 months ago #69926
by waitz
Version 2.73.1+171220
Dropdown in Multiple short text was created by waitz
Is it possible with javascript to change one of the short text fields in a Multiple short text into a standard dropdown list?
I managed with a lot of help to make a preselect dropdown, so I guess it is possible to make a standard dropdown also?
I managed with a lot of help to make a preselect dropdown, so I guess it is possible to make a standard dropdown also?
Version 2.73.1+171220
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
12 years 4 months ago #69935
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 Dropdown in Multiple short text
Have a look at the Autocomplete workaround -
docs.limesurvey.org/Workarounds%3A+Manip...y#and_later_versions
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 27
- Thank you received: 0
12 years 4 months ago #69948
by waitz
Version 2.73.1+171220
Replied by waitz on topic Dropdown in Multiple short text
Thats an autocomplete, which I use elsewhere. What I am looking for now is a normal dropdown box.
If you for example accidentally make the wrong choice in the autocomplete above, the list will not open again until you remove the text which is there.
If you for example accidentally make the wrong choice in the autocomplete above, the list will not open again until you remove the text which is there.
Version 2.73.1+171220
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
12 years 4 months ago #69964
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 Dropdown in Multiple short text
Okay, to do that you will need to use JavaScript to:
- Define the select element (dropdown)
- Hide the text input
- Insert the select elements
- Initially select an option if the question has already been answered
- Insert selected values into the hidden text input when the dropdown is changed
Add the following script to the source of the your question.
Replace "QQ" with the question ID and "NN" with the row number of the text input you would like to replace.
Modify the HTML for the dropdown as required.
- Define the select element (dropdown)
- Hide the text input
- Insert the select elements
- Initially select an option if the question has already been answered
- Insert selected values into the hidden text input when the dropdown is changed
Add the following script to the source of the your question.
Replace "QQ" with the question ID and "NN" with the row number of the text input you would like to replace.
Modify the HTML for the dropdown as required.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var qID = QQ; var inputNum = NN; // Define the select element (dropdown) var select1 = '<select id="select1"> \ <option value="">-- Please Choose --</option> \ <option value="Apples">Apples</option> \ <option value="Oranges">Oranges</option> \ <option value="Pears">Pears</option> \ <option value="Bananas">Bananas</option> \ </select>'; // Hide the text input $('#question'+qID+' li:eq('+(inputNum-1)+') input.text').hide().parent().hide(); // Insert the select elements $('#question'+qID+' li:eq('+(inputNum-1)+')').append(select1); // Initially select an option if the question has already been answered if($('#question'+qID+' li:eq('+(inputNum-1)+') input.text').val()) { $('#question'+qID+' li:eq('+(inputNum-1)+') select').val($('#question'+qID+' li:eq('+(inputNum-1)+') input.text').val()) } // Listener on the dropdowns - insert selected values into hidden text input $('#question'+qID+' select').change(function() { $(this).siblings('span').children('input.text').val($(this).val()); }); // Some styles $('#question'+qID+' select').css({ 'margin':'0.3em 0 0 1em' }); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- waitz
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 27
- Thank you received: 0
12 years 4 months ago #69982
by waitz
Version 2.73.1+171220
Replied by waitz on topic Dropdown in Multiple short text
Yepp, fantastic! Thanks
Version 2.73.1+171220
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
12 years 4 months ago #70010
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 Dropdown in Multiple short text
buddybeers.com/en :cheer:waitz wrote: Yepp, fantastic! Thanks
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.
- Shehrlon_18135
- Offline
- Banned
Less
More
- Posts: 1
- Thank you received: 0
11 years 6 months ago #86717
by Shehrlon_18135
Replied by Shehrlon_18135 on topic Dropdown in Multiple short text
Would it be possible to replace more text elements with dropdowns ?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
11 years 6 months ago #86719
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 Dropdown in Multiple short text
Yes, simply repeat the script with different question IDs or row numbers.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
11 years 6 months ago #86752
by DenisChenu
var qid={QID}
Denis
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Dropdown in Multiple short text
Since 1.91 (or before) you can use :tpartner wrote: Replace "QQ" with the question ID and "NN" with the row number of the text input you would like to replace.
var qid={QID}
Denis
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- Gabriela
- Offline
- Banned
Less
More
- Posts: 30
- Thank you received: 0
11 years 3 months ago #90859
by Gabriela
Replied by Gabriela on topic Dropdown in Multiple short text
is it possible to do the same with an answerID? (#answer1234566)
in a matrix text?
thanks
in a matrix text?
thanks
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
11 years 3 months ago - 11 years 3 months ago #90886
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 Dropdown in Multiple short text
Sure, you can use this with IDs of array text inputs as selectors.
To use an example similar to your other post about time inputs, this code will insert the dropdowns in the first column of the array:
To use an example similar to your other post about time inputs, this code will insert the dropdowns in the first column of the array:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Text inputs to be replaced by dropdowns var dropdownAnswers = $('#answer97841X5X16SQ001_SQ001, #answer97841X5X16SQ002_SQ001, #answer97841X5X16SQ003_SQ001'); // Define the select element (dropdown) var select1 = '<select class="select1 insertedSelect"> \ <option value="">-- Please Choose --</option> \ <option value="Apples">Apples</option> \ <option value="Oranges">Oranges</option> \ <option value="Pears">Pears</option> \ <option value="Bananas">Bananas</option> \ </select>'; // Hide the text inputs $(dropdownAnswers).hide(); // Insert the select elements $(dropdownAnswers).parents('td').append(select1); // Initially select an option if the question has already been answered $('.insertedSelect').each(function(i) { if($(this).parent().find('input[type="text"]').val()) { $(this).val($(this).parent().find('input[type="text"]').val()) } }); // Listener on the dropdowns - insert selected values into hidden text inputs $('.insertedSelect').change(function() { $(this).parent().find('input[type="text"]').val($(this).val()); }); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 11 years 3 months ago by tpartner.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
11 years 3 months ago #90892
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 Dropdown in Multiple short text
Oops, found a bug, use this instead:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Text inputs to be replaced by dropdowns var dropdownAnswers = $('#answer97841X5X16SQ001_SQ001, #answer97841X5X16SQ002_SQ001, #answer97841X5X16SQ003_SQ001'); // Define the select element (dropdown) var select1 = '<select class="select1 insertedSelect"> \ <option value="">-- Please Choose --</option> \ <option value="Apples">Apples</option> \ <option value="Oranges">Oranges</option> \ <option value="Pears">Pears</option> \ <option value="Bananas">Bananas</option> \ </select>'; // Hide the text inputs $(dropdownAnswers).hide(); // Insert the select elements $(dropdownAnswers).closest('td').append(select1); // Initially select an option if the question has already been answered $('.insertedSelect').each(function(i) { if($(this).parent().find('input[type="text"]').val()) { $(this).val($(this).parent().find('input[type="text"]').val()) } }); // Listener on the dropdowns - insert selected values into hidden text inputs $('.insertedSelect').change(function() { $(this).parent().find('input[type="text"]').val($(this).val()); }); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.