- Posts: 14
- 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(){ // Identify this question var thisQuestion = $('#question{QID}'); // Assign column-specific classes $('table.subquestion-list', thisQuestion).addClass('custom-dropdown-array'); $('table.subquestion-list tr', thisQuestion).each(function(i) { $('> *:gt(0)', this).each(function(i){ $(this).addClass('column-'+(i+1)); $(this).attr('data-column', i+1); }); }); // Hide the text inputs in columns 2 $('.column-2 input[type="text"]', thisQuestion).hide(); // Define the select element (dropdown) var select1 = '<select class="inserted-select"> \ <option value="">-- Please Choose --</option> \ <option value="Not for profit">Not for profit</option> \ <option value="Private sector">Private sector</option> \ <option value="Provincial Government">Provincial Government</option> \ <option value="Municipal government">Municipal government</option> \ <option value="Other Source (individual)">Other Source (individual)</option> \ </select>'; // Insert the select elements into column 2 $('.answer-item.column-2').append(select1); // Initial dropdown values in column 2 (if the question has already been answered) $('.answer-item.column-2 input[type="text"]').each(function(i){ if($.trim($(this).val()) != '') { $(this).closest('td').find('.inserted-select').val($.trim($(this).val())); } }); // Hide the text inputs in columns 3 $('.column-3 input[type="text"]', thisQuestion).hide(); // Define the select element (dropdown) var select1 = '<select class="inserted-select"> \ <option value="">-- Please Choose --</option> \ <option value="New donor/partner">New donor/partner</option> \ <option value="Existing donor/partner">Existing donor/partner</option> \ </select>'; // Insert the select elements into column 3 $('.answer-item.column-3').append(select1); // Initial dropdown values in column 3 (if the question has already been answered) $('.answer-item.column-3 input[type="text"]').each(function(i){ if($.trim($(this).val()) != '') { $(this).closest('td').find('.inserted-select').val($.trim($(this).val())); } }); // Hide the text inputs in columns 6 $('.column-6 input[type="text"]', thisQuestion).hide(); // Define the select element (dropdown) var select1 = '<select class="inserted-select"> \ <option value="">-- Please Choose --</option> \ <option value="Volunteer time">Volunteer time</option> \ <option value="Professional services">Professional services</option> \ <option value="Space / facilities">Space / facilities</option> \ <option value="Travel">Travel</option> \ <option value="Equipment / supplies">Equipment / supplies</option> \ <option value="Other">Other</option> \ </select>'; // Insert the select elements into column 6 $('.answer-item.column-6').append(select1); // Initial dropdown values in column 6 (if the question has already been answered) $('.answer-item.column-6 input[type="text"]').each(function(i){ if($.trim($(this).val()) != '') { $(this).closest('td').find('.inserted-select').val($.trim($(this).val())); } }); // Hide the text inputs in columns 7 $('.column-7 input[type="text"]', thisQuestion).hide(); // Define the select element (dropdown) var select1 = '<select class="inserted-select"> \ <option value="">-- Please Choose --</option> \ <option value="Agreement holder">Agreement Holder</option> \ <option value="Sub-agreement holder">Sub-Agreement Holder</option> \ <option value="Sub-sub-agreement holder">Sub-Sub-Agreement Holder</option> \ </select>'; // Insert the select elements into column 7 $('.answer-item.column-7').append(select1); // Initial dropdown values in column 7 (if the question has already been answered) $('.answer-item.column-7 input[type="text"]').each(function(i){ if($.trim($(this).val()) != '') { $(this).closest('td').find('.inserted-select').val($.trim($(this).val())); } }); // Listener on the dropdowns (insert selected values into hidden text input) $('.inserted-select').change(function() { var thisInput = $(this).closest('td').find('input[type="text"]'); $(thisInput).val($(this).val()); checkconditions($(thisInput).val(), $(thisInput).attr('name'), 'text'); }); // Remove existing column widths $('table.subquestion-list col:not(.col-hidden)', thisQuestion).css('width', ''); }); </script>
tpartner wrote: (you will probably need to define both select and column widths with CSS)
<style type="text/css"> table.subquestion-list thead .column-0 { width: 26%; } table.subquestion-list thead .column-1 { width: 6%; } table.subquestion-list thead .column-2 { width: 12%; } table.subquestion-list thead .column-3 { width: 12%; } table.subquestion-list thead .column-4 { width: 8%; } table.subquestion-list thead .column-5 { width: 8%; } table.subquestion-list thead .column-6 { width: 14%; } table.subquestion-list thead .column-7 { width: 14%; } </style>