JavaScript code for time stamps of single responses in form question type - time stamps not shown in data file | XM Community
Skip to main content

Hey everyone!

In our study, one task requires participants to fill in several responses in designated text boxes. The task uses the form question type with 30 text boxes that can, but do not have to be, filled in. We used JavaScript to portray the text boxes one by one, so that the next field is only shown to someone as soon as they start typing in the first one. This worked out fine with the following code:

 

Qualtrics.SurveyEngine.addOnload(function()
{
    /*Positionieren Sie Ihr JavaScript hier, damit es beim Laden der Seite ausgeführt wird*/

});

Qualtrics.SurveyEngine.addOnReady(function() {
  var inputFields = jQuery("#"+this.questionId+" .InputText");

  // Hide all input fields except the first one
  inputFields.slice(1).closest('tr').hide();

  // Attach the input event handler to all input fields
  inputFields.on("input", function() {
    // Get the index of the current field
    var currentIndex = inputFields.index(this);
    
    // Check if the current field is not empty
    if (jQuery(this).val().trim() !== '') {
      // Show the next field if available
      inputFields.eq(currentIndex + 1).closest('tr').show();
    } else {
      // Hide all subsequent fields if the current field becomes empty
      inputFields.slice(currentIndex + 1).closest('tr').hide();
    }
  });
});

Qualtrics.SurveyEngine.addOnUnload(function()
{
    /*Positionieren Sie Ihr JavaScript hier, damit es beim Entladen der Seite ausgeführt wird*/

});

 

In addition, we need time stamps for each response, which are supposed to be included in the data file. Unfortunately, we did not fully achieve this yet: As soon as this code snippet is used, the text boxes do not show up as needed anymore, but are all immediately available. Additionally, the time stamps are not shown in the data file, even if respective embedded data is created. Would be super helpful if someone knew how to add to this code/the survey in order to achieve this!

Thank you very much in advance!

Be the first to reply!

Leave a Reply