Welcome to the LimeSurvey Community Forum

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

Storing date of clicking button event as an answer to a short text question.

  • ligiasilva
  • ligiasilva's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 1 month ago #236323 by ligiasilva
Please help us help you and fill where relevant:
Your LimeSurvey version: Version 3.27.34+220132
Own server or LimeSurvey hosting:
Survey theme/template: vanilla
==================
Hi everyone!

I need to create a survey where I ask people to click on a start button, mentally count some seconds and then press a stop button. Then I need the actual time ineterval between those 2 clicks to be recorded as an answer. I know a bit of JS so I thought about creating a date stamp (using simple new Date() ) to each clicking (using the onclick event) and later calculating the difference between them. I'm trying to make those date stamps to get stored as an answer in another short text answer in the same group, that could be later hidden. But I don't know how to refer to that input field in the answer. Could you help me figure out how to do this. Please bear in mind that I'm not a real IT person, I just know some very basic HTML and JS. Here is the code I have so far (which does not work at all yet)

<script>
function dateevent ( ) {
  var date = new Date( year,month,day,hours,minutes,seconds );
&584111X16091X336280 = date;
}
</script>
<button id="button1" onclick="dateevent">start</button>
<button id="button2" onclick="dateevent">stop</button>

would still need to do a second place to hold the stop button clicking date, but for now, nothing is being stored in that answer input field. 

Any help will be very appreciated.

Lígia
 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 1 month ago #236327 by Joffm
Hi, I can show this
Code:
<button class="btn btn-success" id="button1" onclick="dateevent1()" type="button">start</button>
<button class="btn btn-danger" id="button2" onclick="dateevent2()" type="button">stop</button>
 
<script type="text/javascript" charset="utf-8">
    $(document).ready(function(){
          $('#button2').hide();
    });
 
function dateevent1(){
  var thisQuestion = $('#question{QID}');
  var date1 = Date.now();
  $('input[type=text]:eq(0)', thisQuestion).val(date1);
  $('#button1').hide();
  $('#button2').show();
}
function dateevent2(){
  var thisQuestion = $('#question{QID}');
  var date2 = Date.now();
  $('input[type=text]:eq(1)', thisQuestion).val(date2);
  $('#ls-button-submit').trigger('click'); 
}
</script>
 
<style type="text/css">.answer-container {
  display: none;
}
</style>

First hide the "Stop"-Button
After clicking the "Start"-Button hide it but show the "Stop"-Button
After clicking the "Stop"-Button proceed to the next question.

Store the times in a question of type "multiple short text"

In the next question do the calculation and show the result

 

 

 
 

File Attachment:

File Name: limesurvey...8428.lss
File Size:17 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • ligiasilva
  • ligiasilva's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 1 month ago #237221 by ligiasilva
Thank you Joffm a lot for the help!

It seems to work fine for what I need. Just 2 things:
1)can I just store the time difference between the 2 clicks as an answer to myself and not show it to the participants? That could interfere with their further answers. When I simply hide the second question limesurvey says there is inconsistency and doesn't let me activate the survey.

Also, one of the times I tested I received NAN miliseconds... Can that be associated with any specific interval that it is not calculating? I counted around 10 seconds. But now that I try to replicate it it is working fine...

Thank you a lot, saved me tons of time. Sorry for the late response, busy week.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 1 month ago - 2 years 1 month ago #237223 by Joffm
In a real survey you hide this question.
And you do this calculation in a question of type equation. Then the value is stored.

You only display it during your tests.
And you also should show the timestamps.
This way you may see when and why you get a NAN.

Joffm 

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

Please Log in to join the conversation.

  • ligiasilva
  • ligiasilva's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 1 month ago #237225 by ligiasilva
Did the settings as you suggested and it worked fine!! Thank you very much for the help, just made my day to have this solved so quickly.

Please Log in to join the conversation.

  • ligiasilva
  • ligiasilva's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 1 month ago #239077 by ligiasilva
Hello Joffm!

I'm integrating the solution you gave me in a previously used survey. The 2 questions from your solution are in conflict with a 3rd array question that must be presented in the same group. The subquestions and array options of that 3rd question are not appearing. Any idea why? already deleted it and redone it again. you can find this in the question group: ProspectiveM3Ton120. in the attached file

Any help would be very useful, thanks a lot

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 1 month ago #239081 by Joffm
Yes, I know.

This is, because people never explain everything they want to do.
You see that I use the question text of the "short text" question, but hide the answer container.

And this container is group wide hidden.

So to only hide the answer container of this question, you have to re3fer to it.
Change to "#question{QID} .answer-container { display: none; }

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • ligiasilva
  • ligiasilva's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 1 month ago #239139 by ligiasilva
Sorry, I assumed that explaining the whole survey would be a bit tedious and unnecessary.
Your solution worked, makes sense, didn’t know that unless specified the style applies to the whole group.
Thanks a lot for the help!

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 1 month ago #239160 by Joffm

unless specified the style applies to the whole group.

Not exactly to the whole group (is you use the word "group" as a LimeSurvey group).
The style applies to everything on the screen.
Therefore you often use classes to specify if an element is affected by a style or not.

You see, you also could have added a css class like "hide-answer" to prospM3Ton120
and change the css code to 
Code:
<style type="text/css">
.hide-answer .answer-container {
  display: none;
}
Only in elements with class ".hide-answer"  the answer container is hidden.

I assumed that explaining the whole survey would be a bit tedious and unnecessary.

As you see, it is not.
You see, your initial question was 

I need to create a survey where I ask people to click on a start button, mentally count some seconds and then press a stop button. 

and this is what you got.

By the way: Do you really think it a good idea to display all these things on one page?
I'd display these questions one after the other.
1. Listen to the music
2. Let's check your ability of time estimation.
3. The array question

Joffm

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose