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
4 hours 7 minutes ago - 4 hours 7 minutes 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: 4 hours 7 minutes ago by ligiasilva.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 hour 20 minutes ago - 1 hour 20 minutes 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 hour 20 minutes ago by Joffm.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose