Insert a timestamp on click | XM Community
Solved

Insert a timestamp on click

  • 13 May 2020
  • 4 replies
  • 229 views

Badge +1

I have the JavaScript for inserting a timestamp upon a click. We are using the survey for an audit and need to have auditor click the time they start each task. I do not want to use time began survey, as I need multiple timing fields for different actions. The JavaScript I have when I copy it to a new question , once I test it, it populates into the one below, and it won't populate more than once.
timing.JPG I know there is something wrong with the code but I am not sure what.

icon

Best answer by rondev 13 May 2020, 07:13

View original

4 replies

Userlevel 7
Badge +22

Please paste the JS you are using here.

Badge +1




Userlevel 7
Badge +22

Create a text entry form field question with 1 field. In the click to write statement for field 1 paste the below code:

In the JS onReady function of the same question paste the below code:
var that =this;
jQuery("#"+that.questionId+" .InputText").attr("readonly",true);
jQuery("#"+that.questionId+" #button").on('click',function(){
jQuery("#"+that.questionId+" .InputText").val(new Date());   
   });

Badge

Hey! Thanks so much for posting this, it's almost exactly what I need. I'm wondering if there is a way to do this but instead of it recording it as a text/string variable, it gives the timestamp in military time? I want to export it out eventually and use math operations to subtract begin from end times to see how long something took that the respondent was observring. Any help is much appreciated.

Leave a Reply