- Posts: 72
- Thank you received: 10
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript"> $(document).ready(function() { // A function to show subsequent rows of an array as options are checked function expandingArray(qID) { // Build an array of the question rows var arrayRow = '#question' + qID + ' table.question tbody tr'; // Initially hide all rows unless an input was previously checked $( arrayRow ).each(function(i) { if ( $( arrayRow + ':eq(' + i + ') input.radio:checked' ).length != 0 ) { $(this).attr('name', 'clickedRow'); } else { $(this).attr('name', 'hidden').hide(); } }); // Now show the first hidden row addRow(); // Add another row when an option is checked for the first time $( '#question' + qID + ' td.answer input.radio' ).click(function (event) { if ($(this).parents('tr:eq(0)').attr('name') != 'clickedRow') { addRow(); $(this).parents('tr:eq(0)').attr('name', 'clickedRow'); } // The original function of the click event checkconditions(this.value, this.name, this.type); }); // Add another row when an table cell is clicked for the first time $( '#question' + qID + ' table.question tbody td' ).click(function (event) { if ($(this).parents('tr:eq(0)').attr('name') != 'clickedRow') { addRow(); $(this).parents('tr:eq(0)').attr('name', 'clickedRow'); } }); // Function to add a row function addRow() { $( arrayRow + '[name="hidden"]:first' ).attr('name', 'visible').show(); // Now, scroll down $("html, body").animate({ scrollTop: $(document).height() }, 1000); } } // Call the function with a question ID expandingArray(QQ); }); </script>
var arrayRow = '#question' + qID + ' table.question tbody tr';
var arrayRow = '#question' + qID + ' table.ls-answers tbody tr';
$( '#question' + qID + ' table.question tbody td' ).click(function (event) {
$( '#question' + qID + ' table.ls-answers tbody td' ).click(function (event) {
$(this).parents('tr:eq(0)').attr('name', 'clickedRow'); // if you also want to hide the answered row: $(this).parents('tr:eq(0)').attr('name', 'clickedRow').hide();
$(this).parents('tr:eq(2)').attr('name', 'ls-heading').hide();
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var thisQuestion = $('#question{QID}'); // Initially hide all but the first row $('tr.answers-list:gt(0)', thisQuestion).hide(); // Listener on the radios $('input:radio', thisQuestion).on('click', function(e) { var thisRow = $(this).closest('tr'); var nextRow = $(thisRow).next('tr.answers-list'); if(nextRow.length > 0) { // Hide this row and show the next $(thisRow).fadeOut(300, function(e) { $(nextRow).fadeIn(300); }); } else { // No next row so hide the table $('table.ls-answers', thisQuestion).fadeOut(300); } }); }); </script>