Welcome to the LimeSurvey Community Forum

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

Refer in Q2 the number of multiple short text answers created in Q1

  • ligiasilva
  • ligiasilva's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 month 2 weeks ago - 1 month 2 weeks ago #268695 by ligiasilva
Please help us help you and fill where relevant:
Your LimeSurvey version: 6.10.0+250106
Own server or LimeSurvey hosting: UC limesurvey
Survey theme/template:
==================

I have a script that a few contributors here helped me with, that creates a button that stores date events in a list that is then stored as a multiple short text answer. This works as a way for the user to point to relevant moments during an experiment. The number of short texts is not defined as priori, and is created as the user taps on the button. What I get as answer is a list of dates separated by ",". Now I want to create a following question where the user will describe what was relevant in the moments he/she decided to mark as relevant. For this, I wanted the question to read "You marked X moments as relevant, can you describe why?" How can I refer to this X as the number of multiple texts dynamically created in the previous question?

Here is the code I have been using:

</script>

<div id="buttonplacement"><button id="tapbutton" type="button">Marcar</button></div>
<script type="text/javascript" data-author="Tony Partner">
    
    $(document).on('ready pjax:scriptcomplete',function(){
        
        // Identify this question
        var thisQuestion = $('#question{QID}');
        var thisTextarea = $('textarea.form-control:eq(0)', thisQuestion);
        
        var timestamps = ;
        if($.trim($(thisTextarea).val()) != '') {
            timestamps = $.trim($(thisTextarea).val()),split(',');
        }        
        
        // Listener on the button
        $('#tapbutton').on('click', function(e) {
            var newTimeStamp = Date.now();
            
            timestamps.push(newTimeStamp);
            
            $(thisTextarea).val(timestamps).trigger('keyup');
        });
    });
</script>

Thank you all for the help.
Last edit: 1 month 2 weeks ago by ligiasilva.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 2 weeks ago - 1 month 2 weeks ago #268698 by Joffm
Hi,
it's always better to provide e lss export of these relevant question.

Then you avoid the typo here
 var timestamps = ;
instead of
 var timestamps = ;

Now, what can you do?
My idea is to use a question of type"multiple short text" with two subquestions.
1. The timestamps
2. The count of timestamps

Then you may use this - slightly adapted - script.
Code:
<div id="buttonplacement">
   <button id="tapbutton" type="button">TAP</button>
</div>

Code:
<script type="text/javascript" data-author="Tony Partner">
    
    $(document).on('ready pjax:scriptcomplete',function(){
        
        // Identify this question
        var thisQuestion = $('#question{QID}');
        var thisTextarea = $('input[type=text]:eq(0)', thisQuestion);
        var thisCountarea = $('input[type=text]:eq(1)', thisQuestion);
        
        var timestamps = [];
        if($.trim($(thisTextarea).val()) != '') {
            timestamps = $.trim($(thisTextarea).val()),split(',');
        }        
        
        // Listener on the button
        $('#tapbutton').on('click', function(e) {
            var newTimeStamp = Date.now();
            
            timestamps.push(newTimeStamp);
            
            $(thisCountarea).val(timestamps.length);
            $(thisTextarea).val(timestamps).trigger('keyup');
        });
      
    });
</script>


And some styling
Code:
<style type="text/css">#question{QID} .answer-container {
        display: none;
    }
        
    #buttonplacement {
        text-align: center;
    }
</style>


You will get this
 

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 month 2 weeks ago by Joffm.

Please Log in to join the conversation.

  • ligiasilva
  • ligiasilva's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 month 2 weeks ago #268717 by ligiasilva
Thank you Joffm.

This worked really nice. I was thinking I had to make Q2 go through Q1 and parse it in the ','. But this is much easier, counting Q1 length after each button press and storing this still in Q1 as SQ002. Then just referring to Q1SQ002 in Q2. Just learned there is a button for this referring to previous answers, which I thought would also be a problem...

Thank you a lot!

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose