- Posts: 72
- Thank you received: 10
Ask the community, share ideas, and connect with other LimeSurvey users!
$(document).ready(function(){ // Hide all but the first question $('.question-container').not(':eq(0)').hide(); // Identify some elements var nextButton = $('#movenextbtn, #movesubmitbtn'); var firstQ = $('.question-container:first'); var lastQ = $('.question-container:last'); // Text for the submit button var nextText = 'Next'; var submitText = 'Submit'; $(nextButton).text(nextText); // Insert a Previous button var previousButton = $('<button type="button" class="button btn btn-lg btn-default" style="display:none">Previous</button>').appendTo($(nextButton).closest('#navigator-container').find('.save-all.text-left')); // Listener on the submit button $(nextButton).on('click', function(e) { // Identify some elements var visibleQ = $('.question-container:visible'); var nextQ = $(visibleQ).next('.question-container'); // If there is a next question if(nextQ.length > 0) { // Prevent default action e.preventDefault(); // Show the next question $(visibleQ).fadeOut(300, function(e) { $(nextQ).fadeIn(300, function(e) { if($(lastQ).is(':visible')) { $(nextButton).text(submitText); } }); }); // Handle the submit button text $('#navigator-container').fadeOut(300, function(e) { $(previousButton).show(); if($(lastQ).is(':visible')) { $(nextButton).text(submitText); } $('#navigator-container').fadeIn(300, function(e) { $('#navigator-container button').prop('disabled', false).removeClass('disabled active'); }); }); } // No next question so submit the page else { $(nextButton).removeClass('active'); } }); // Listener on the previous button $(previousButton).on('click', function(e) { // Identify some elements var visibleQ = $('.question-container:visible'); var prevQ = $(visibleQ).prev('.question-container'); e.preventDefault(); // Show the previous question $(visibleQ).fadeOut(300, function(e) { $(prevQ).fadeIn(300); }); // Handle the previous button visibility $('#navigator-container').fadeOut(300, function(e) { if($(firstQ).is(':visible')) { $(previousButton).hide(); } $('#navigator-container').fadeIn(300, function(e) { $('#navigator-container button').prop('disabled', false).removeClass('disabled active'); }); }); }); });
$(document).ready(function(){ // Hide all but the first question $('.question-container').not(':eq(0)').hide(); // Identify some elements var nextButton = $('#movenextbtn, #movesubmitbtn'); var firstQ = $('.question-container:first'); var lastQ = $('.question-container:last'); // Text for the submit button var nextText = 'Next'; var submitText = 'Submit'; $(nextButton).text(nextText); // Listener on the submit button $(nextButton).on('click', function(e) { // Identify some elements var visibleQ = $('.question-container:visible'); var nextQ = $(visibleQ).next('.question-container'); // If there is a next question if(nextQ.length > 0) { // Prevent default action e.preventDefault(); // Show the next question $(nextQ).fadeIn(600, function(e) { if($(lastQ).is(':visible')) { $(nextButton).text(submitText); } }); // Handle the submit button text and scrolling $(nextButton).fadeOut(150, function(e) { if($(lastQ).is(':visible')) { $(nextButton).text(submitText); $('html, body').animate({ scrollTop: $(document).height() }, 1000); } else { $('html, body').animate({ scrollTop: $(nextQ).offset().top }, 1000); } $(nextButton).fadeIn(150, function(e) { $('#navigator-container button').prop('disabled', false).removeClass('disabled active'); }); }); } // No next question so submit the page else { $(nextButton).removeClass('active'); alert($(document).height()); } }); });
var nextQ = $(visibleQ).next('.question-container');
var nextQ = $(visibleQ).nextAll('.question-container:not(.ls-irrelevant):eq(0)');