Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Naviguate between subquestions of dynamic array

  • declabo
  • declabo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 3 months ago #239303 by declabo
Please help us help you and fill where relevant:
Your LimeSurvey version: Version 5.3.6+220321
Own server or LimeSurvey hosting: own server
Survey theme/template: fruity
==================
Dear all,
I have set an array that is dynamic : once a response is selected the current subquestion fades off and the next subquestion fades in. I used the following code found on this great forum :
Code:
<script type="text/javascript" charset="utf-8">
 
    $(document).on('ready pjax:scriptcomplete',function(){
    
        var thisQuestion = $('#question{QID}');
        
        // Initially hide all but the first row
        $('tr.answers-list:gt(0)', thisQuestion).hide();
      
        // Listener on the radios
        $('input:radio', thisQuestion).on('click', function(e) {
            var thisRow = $(this).closest('tr');
            var nextRow = $(thisRow).next('tr.answers-list');
            console.log(nextRow)
            if(nextRow.length > 0) {
                // Hide this row and show the next
                $(thisRow).fadeOut(300, function(e) {
                    $(nextRow).fadeIn(300);
                });
            }
            else {
                // No next row so hide the table
                $('table.ls-answers', thisQuestion).fadeOut(300);
            }
        });
    });
 
</script>
The thing is I need the participant to be able to correct their responses. I added a button to go back to the previous subquestion but it is not working. Could you help me this ? Here is my code :
Code:
<button onclick="showpreviousRow();" style="float: right;" type="button"> Check your previous response </button>
<script type="text/javascript" charset="utf-8">
  function showpreviousRow() {
    var thisQuestion = $('#question{QID}');
     $('tr.answers-list:gt(0)', thisQuestion).show(); // Initially hide all but the first row
    var currentRow = $('tr.answers-list', thisQuestion).closest('tr');
    var prevRow = $(currentRow).prev('tr.answers-list');
    $(currentRow).fadeOut(300, function(e) {
    $(prevRow).fadeIn(300);
    });
    }
</script></p>
Thank you very much in advance

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 3 months ago #239304 by holch
Back won't work because it is per question. Your array is one question with various sub questions. So you either need to include a way to go back to the previous subquestion or you just create an array question with one subquestion. Then the back button will work.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Please Log in to join the conversation.

  • declabo
  • declabo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 3 months ago - 1 year 3 months ago #239305 by declabo
I actually set a new button to naviguate between the subquestions as it is done in the first code section.
That might be my javascript code that is buggy (the second code part)
This variable
Code:
$('tr.answers-list', thisQuestion).closest('tr');

does not give me the current subquestion but the entire list of the subquestions. I can not retrieve it as in the first part, I am not sure how
Last edit: 1 year 3 months ago by declabo.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 3 months ago - 1 year 3 months ago #239307 by tpartner
I'm wondering about the behaviour...

What if they want to check the answer in the previous row but when they get there it is correct? How do they then proceed without changing that answer?

What if they want to check answer(s) more than one row previous?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 1 year 3 months ago by tpartner.

Please Log in to join the conversation.

  • declabo
  • declabo's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 3 months ago #239427 by declabo
You are right tpartner. So at the end, we created a survey displayed question by question and showed each time an array with one subquestion only. It works well.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose