Welcome to the LimeSurvey Community Forum

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

Save data from js to results

More
5 years 2 months ago #217511 by Sonjawnklr
Hello everybody,

I have some audioplayback, where the participant is promped to press the spacebar a varying amount of times. I can already log the total number of presses to the console.
Is it possible to save that to the results file somehow? 
Below is my WIP code:
Code:
<div style="text-align: center;"><img alt="" src="/limesurvey-wipsy/upload/surveys/623622/images/Anleitung.JPG" style="width: 800px;" /></div> <div class="ckeditor-html5-video" style="text-align:center;"> <video controls="controls" controlslist="nodownload" id="vid" src="/limesurvey-wipsy/upload/surveys/623622/files/Achtsamkeits%C3%BCbung.mp3"> </video> </div> <script>     $(document).ready(function() {         $('#ls-button-submit').hide();         var vid = document.getElementById('vid');         var count = 0;         vid.onplay = function() {             document.getElementById('vid').style.visibility = "hidden";               document.body.onkeyup = function(e){                 if(e.keyCode == 32){                   console.log(count++);                 };             };         };           vid.onended = function() {             $('#ls-button-submit').show().trigger('click');               // Send total count to results!                console.log(count)         }     }); </script>

I would like to log the count to the results file as a variable in the vid.onended function (see comment). 

Thank you very much for your help! :) 
The topic has been locked.
More
5 years 2 months ago #217520 by tpartner
If your script is in the text of a short-text type question:

Code:
document.body.onkeyup = function(e){ if(e.keyCode == 32){ console.log(count++); $('#question{QID} input:text').val(count++).trigger('keyup'); } };

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
5 years 2 months ago #217535 by Sonjawnklr
Hey,
thanks for your quick response. That worked perfectly. I also hid the text field, so the participant won't notice it. :)
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose