Script to ask array sub questions one at a time.

4 years 2 months ago #110865 by Bigred01
Bigred01 created the topic: Script to ask array sub questions one at a time.
Hi everyone. Just wanted to share this function that will let you ask array questions one at a time if you have a large list. Can help fight people straight-lining if they don't see a huge table.

Any feedback as to how it can be improved would be much appreciated.

Add this to a js file:
//Show array rows one at a time
arrayRowShowHide = function (qId) {
    var questionId = '#question' + qId;
    var ansArr = [];
    $(questionId + ' .answers-list').hide();
    //build array of possbile answers
    $(questionId + ' .answers-list').each(function () {
            $(this).children('th').children('input').attr('id'), //sub-q input id
            $(this).attr('id') //sub-q tr id
    var lastAnswer = ansArr.length - 1;
    $('#' + ansArr[0][1]).show();
    $('.answer-item').click(function (index) {
	//check for and hide questions answered then show first one that's un-answered.
        $.each(ansArr, function (index) {
            if (document.getElementById(ansArr[index][0]).value != "") {
                $('#' + ansArr[index][1]).hide();
            else {
                $('#' + ansArr[index][1]).show();
                return false;
	//auto next if last qub-q is answered.
        if (document.getElementById(ansArr[lastAnswer][0]).value != "") {

And you can call it with this in your question:
$(document).ready(function() {
The following user(s) said Thank You: Ben_V

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!