Insert a timestamp on click | XM Community
Skip to main content
Solved

Insert a timestamp on click

  • May 13, 2020
  • 4 replies
  • 463 views

Forum|alt.badge.img+3

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.

Best answer by rondev

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());   
   });

4 replies

rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • May 13, 2020

Please paste the JS you are using here.


Forum|alt.badge.img+3





rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • Answer
  • May 13, 2020

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());   
   });


Forum|alt.badge.img
  • February 7, 2023

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.