OnSubmit function in JS is working for preview & anonymous link but not working in website project | XM Community
Question

OnSubmit function in JS is working for preview & anonymous link but not working in website project

  • 6 November 2020
  • 1 reply
  • 121 views

Badge

Hi Everyone,

We have a survey which is used in a website feedback project. We have a javascript added in survey to Question Q2 which sets the value in ED depending on the answer choice selected by the customer We then use this embedded data in Q3 to display the value in the text of Question 3 in the survey so Q3 looks like this: How easy was it to ${e://Field/Q3CESText}? The logic applied is working perfectly fine when tested on the preview or anonymous link but it is not working when testing the survey on the client website through website project. That means the javascript is might not working when testing the survey on the mentioned website I tried testing with other test sites but it is not working on them as well Can anybody please help to find the cause? The javascript is fetching the value correctly on preview link: https://tuigroup.eu.qualtrics.com/jfe/preview/SV_1AlTOvB9aIxhDOR?Q_CHL=preview&Q_SurveyVersionID=current
Below is the code we are using in Q2 to set the value of Embedded data in Q3:
Qualtrics.SurveyEngine.addOnPageSubmit(function(type)   
{
/*Place your JavaScript here to run when the page is unloaded*/
var q4 = this.getSelectedChoices ();
if (q4 == "1" ){
Qualtrics.SurveyEngine.setEmbeddedData('Q3CESText', "Ziele erkunden und Urlaubsideen erhalten");
}
else if (q4 == "2"){
Qualtrics.SurveyEngine.setEmbeddedData('Q3CESText', "nach einem konkreten Urlaub zu suchen");
}
else if (q4 == "3"){
Qualtrics.SurveyEngine.setEmbeddedData('Q3CESText', "eine Buchung vorzunehmen");
}
else if (q4 == "4"){
Qualtrics.SurveyEngine.setEmbeddedData('Q3CESText', "Ihre aktuelle Buchung einzusehen oder zu bearbeiten");
}
else if (q4 == "5"){
Qualtrics.SurveyEngine.setEmbeddedData('Q3CESText', "${e://Field/Brand} zu kontaktieren");
}
else if (q4 == "6"){
Qualtrics.SurveyEngine.setEmbeddedData('Q3CESText', "einen Sitzplatz zu reservieren / online einzuchecken");
}
else {
Qualtrics.SurveyEngine.setEmbeddedData('Q3CESText', "Ihr heutiges Ziel zu erreichen");
}
});

We have tried putting the code in Onload and other functions but it doesn't work as intended.


1 reply

Userlevel 7
Badge +21

Your case would be more reliably served by using Carry Forward Answer Choices.

Leave a Reply