I am trying to have a piped text translated from English to another the language selected by the survey on starting the survey using JavaScript.
I put together this script below but it failed. Any idea if this is possible? or ideas as to what I might be missing?
Thanks in advance.
Qualtrics.SurveyEngine.addOnload(function() {
// Get the selected language choice
var selectedLanguage = "${e://Field/LanguageChoice}";
// Get the current value of the piped text
var pipedTextValue = "${e://Field/added%20info}";
// Trim whitespace from the piped text value
pipedTextValue = pipedTextValue.trim();
// Define the specific text to search for
var searchText = "This is the current text.";
// Check if the piped text contains the specific text
if (pipedTextValue.includes(searchText)) {
// Check if the selected language is French
if (selectedLanguage === "French") {
// Replace the content of the preferenceInsight element with the French translation
document.getElementById("preferenceInsight").innerText = "French translation of the text";
}
} else {
// Log a message to the console for debugging if the specific text is not found
console.log("The specific text was not found in the piped text value:", pipedTextValue);
}
});
</script>