Welcome, Guest
Username: Password: Remember me

TOPIC: Script to ask array sub questions one at a time.

Script to ask array sub questions one at a time. 2 weeks 2 days ago #110865

  • Bigred
  • Bigred's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 12
  • Thank you received: 3
  • Karma: 1
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 () {
 
        ansArr.push([
            $(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 != "") {
            $('#movenextbtn').click();
        }
    });
};
 

And you can call it with this in your question:
 
<script>
$(document).ready(function() {
 
     arrayRowShowHide('{QID}');
 
});
</script>
 
The administrator has disabled public write access.
The following user(s) said Thank You: Ben_V
Moderators: ITEd
Time to create page: 0.118 seconds
Donation Image