Does the “New Survey Experience” require doing something additional to make jQuery work? | XM Community
Skip to main content

 

I switched a survey over to the “New Survey Experience.” In the prior survey version, the javascript that I used in the question to create an embedded variable works as expected. I’ve included the query below. When I switched to the “New Survey Experience” the embedded variable is no longer being created and I get the following errors in the console: “Error executing custom js: ReferenceError: o is not defined” and “Listener must be a named function”.

Does the “New Survey Experience” require doing something additional to make jQuery work?

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
  var essayText = jQuery("#" + this.questionId + " .InputText").val();
 var htmlText = essayText.replace(/\n/g, "<br>");
 Qualtrics.SurveyEngine.setEmbeddedData("FormattedResp", htmlText);
});

Hi,

You need to include jQuery from a CDN in your survey or theme header in the new survey experience.

Your code will need to be updated as well. Elements names, classes and IDs are not the same. setEmbeddedData method is not usable anymore either, you’ll need to use setJSEmbeddedData and prefix your EDs with __js_ to access them in your custom codeSee the question API for usage.


Thanks for the additional information. It still didn’t work. This is the script that I had used in my survey header (source).

 <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><script type="text/javascript">Qualtrics.SurveyEngine.addOnReady(function() { jQuery('#Plug').attr('style', 'display:none !important');});</script>

 

Do you have recommended changes? (I had just found it online when I searched how to load jQuery from a CDN, so it could be way off.)

 

 


Hi,

Try the following for a new survey taking experience version that doesn’t require jQuery:

Qualtrics.SurveyEngine.addOnPageSubmit(function () {

var textarea = document.querySelector("#question-" + this.questionId + " .text-input");
var htmlText = textarea ? textarea.value.replace(/\n/g, "<br>") : "";
Qualtrics.SurveyEngine.setJSEmbeddedData("FormattedResp", htmlText);

});

Your survey flow should look like this:

 


And since we’re at it, here’s the fix for your #Plug:

 


That worked! Thank you so much!!


Leave a Reply