lundi 25 mai 2020

Show last checked + two more (from array)

I have questionnaire of 20 checkboxes pulled from a JSON file into an array.

When an item is checked I push the question value to an array [1,3] that also stores in a cookie – so when the user returns, questions 1 + 3 remain checked.

var questions = ["1", "2", "3" ... "20"];

jQuery(this).change(function() {
    var question_value = jQuery(this).val();

    if (jQuery(this).is(':checked')) {
        Cookies.set('completed', questions_completed);
        questions_completed.push(question_value);
    } else {
        // splice/remove the item from the array    
    }
});

var questions_completed = [1, 3]; // stores checked/completed questions number

What I want to do is show 3 checkboxes at a time (not all 20).

The last question appears at the top (checked) and then two more from the list (not checked) until all questions are completed.

I can't figure out how to approach this correctly – I need to compare the completed array with the questions array, but I can't seem to do this within creating multiple loops within loops.




Aucun commentaire:

Enregistrer un commentaire