- Posts: 27
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<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>
buddybeers.com/en :cheer:waitz wrote: Yepp, fantastic! Thanks
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.
<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>
<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>