Save text in entry value in java | XM Community
Skip to main content

I am using a matrix table with allow entry text function. For some questions I want to save the text. I found that I can use piped text of one of those question, for example using ${q://QID330/ChoiceTextEntryValue/3} 

I am trying to save the text in a variable in java. So, I try to use the following codes that i see in other posts:

var  itemtext= "${q://QID330/ChoiceTextEntryValue/3}";
var  itemtext=  jQuery("#QID330 input type=text]").eq(0).val();

var itemtext= jQuery("#QID330 option:selected").text();

 

But, none one works, any idea what can work for this?

 

the code you provided might not work as expected because it looks like you are trying to mix JavaScript variables and Qualtrics piped text placeholders incorrectly.

To correctly retrieve the text entered in the matrix table, you should use the Qualtrics JavaScript API rather than directly using jQuery to select elements. Here's a way to do it:

Qualtrics.SurveyEngine.addOnload(function() {
    // Retrieve the text entered in the matrix table cell
    var itemText = "${q://QID330/ChoiceTextEntryValue/3}";

    // Use the retrieved text as needed (e.g., display it in the console)
    console.log(itemText);
});
 

The above code will correctly retrieve the entered text from the specified matrix table cell with an "allow text entry" function and save it to the itemText variable. Note that this code should be placed within the "Survey" section of your Qualtrics survey.

 


Hey @Josang ,

Great to e-meet you.

The Java-script code var  itemtext= "${q://QID330/ChoiceTextEntryValue/3}", should work (see the working screenshot below).

However, make sure that, you have added the Javascript in the question asked AFTER your metrix question where the 2 questions (metrix and the question with JS) should not be on the same page for the JS to work.

Hope this helps.


 

 


Hi all, 

I wanted that this was saved during the same question, because I want to use it in the next question. So, it works in the following way:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {

var  itemtext=    jQuery("#QID330 input type=text]").eq(3).val();
});

 

I was using a number row incorrect in eq(), so I always should check that!

 

Thank you!!


Leave a Reply