- Posts: 103
- Thank you received: 5
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(); } } // Call the function with a question ID expandingArray(QQ); }); </script>
<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(); // Scroll down $("html, body").animate({ scrollTop: $(document).height() }, 1000); } } // Identify this question var questionID = {QID}; // Call the function with a question ID expandingArray(questionID); }); </script>