Replicate the text input of a text entry question to a hidden text entry question | XM Community
Solved

Replicate the text input of a text entry question to a hidden text entry question

  • 30 April 2024
  • 5 replies
  • 34 views

Badge +3

Hi all,

We have a text entry (open-ended) question after an NPS question. Our client wants to add 3 new text entry questions (for Detractors, Passives, Promoters), so every respondent will see only 1 of the 3 questions. We want to pass the text input from these 3 questions to the initial question. The initial question must be hidden as we won’t show it anymore. We want to keep the initial question for export purposes and Text IQ.

I included the three questions on the same page and I save the text input to an embedded data field like the picture below

 

I added a page break after the three questions. Then I added the question I want to hide and replicate the value that it is saved in the embedded data field, followed by a random question

 

This works but when someone leaves the survey incomplete after submitting the page with the 3 questions, the value is not replicated to the hidden question

 

Any ideas will be appreciated,

 

Thanks

icon

Best answer by TomG 1 May 2024, 15:16

View original

5 replies

Userlevel 4
Badge +8

Hi @Apostolos99 ,

Try adding by below code:

Qualtrics.SurveyEngine.addOnload(function() {
    // Get the value from the embedded data field
    var value = "${e://Field/YourEmbeddedDataField}";

    // Set the value of the hidden question
    jQuery("#QID").val(value); // Replace "QID" with the ID of your hidden question
});
 

Userlevel 7
Badge +21

A simpler option would be have the question text as an embeded data. Use branch logic to set the value of this ED.

Badge +3

Hi @Nanditha MM 

 

I have tried your suggested code but I am still not able to make this work. I don’t know the reason but I will keep working using your idea as it makes more sense to give the value to the hidden question in advance. That’s the code I have used in my 3 questions

Qualtrics.SurveyEngine.addOnload(function()
{
    jQuery("#"+this.questionId+" .InputText").on('blur',function(){

    var score = jQuery(this).val();
    Qualtrics.SurveyEngine.setEmbeddedData('StoreId', score);
        

});    

Qualtrics.SurveyEngine.addOnload(function() {
    // Get the value from the embedded data field
    var value = "${e://Field/StoreId}";

    // Set the value of the hidden question
    jQuery("#QID3").val(value); // Replace "QID" with the ID of your hidden question
});

    });

 

Thanks

Userlevel 7
Badge +27

@Apostolos99,

Move the hidden question to the same page as the three new question as the last question on the page. Then add this JS to it:

Qualtrics.SurveyEngine.addOnload(function() {
   jQuery(this.questionContainer).hide();
});

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
   jQuery("#"+this.questionId+" .InputText").val(jQuery(".InputText:first").val());
});

 

Badge +3

Hi @TomG ,

 

that worked, thank you very much 🙂

Leave a Reply