Hi everyone!
I'm trying to set embedded data so that I replace apostrophes ( ' ) in a text response with a backslash apostrophe ( \\' ) using javascript.
I was able to figure out the code itself. Here's what I have:
var first = "${q://QID2/ChoiceTextEntryValue/1}";
var first_mod = first.replace(/'/g, "\\\\'");
Qualtrics.SurveyEngine.setEmbeddedData("first", first_mod);
var last = "${q://QID2/ChoiceTextEntryValue/2}";
var last_mod = last.replace(/'/g, "\\\\'");
Qualtrics.SurveyEngine.setEmbeddedData("last", last_mod);
Ideally, I'd set this in the question itself. However, I've tried including it under the header, "Qualtrics.SurveyEngine.addOnUnload" and "Qualtrics.SurveyEngine.addOnPageSubmit" based on a few other help pages I've found. In all cases, the embedded data values are not set. (Help pages I based this on are here, here, and here for reference.)
I've only been able to get it to work by putting the above code under the header "Qualtrics.SurveyEngine.addOnload" on a completely different question on the next page, which is not ideal.
My question is: How can I set the embedded data through javascript on the actual question, itself? I'd really rather not have the javascript associated with a completely different question. I've attached some screenshots, in case that's helpful. Let me know if there's anything I can clarify.


Setting embedded data with javascript for a question on OnUnload or OnPageSubmit
Best answer by jackorg
Hi Tom, nevermind, I found the answer in a different question (from you)! So thanks for all your help.
For anyone wondering, here's the solution to get dropdown options to send to embedded data through JS:
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
var account = jQuery("#QID58 option:selected").text();
var account_mod = account.replace(/'/g, "\\\\'");
Qualtrics.SurveyEngine.setEmbeddedData("account", account_mod);
});
Sign up
Already have an account? Login
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login to the Community
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join.
No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Login with Qualtrics
Welcome! To join the Qualtrics Experience Community, log in with your existing Qualtrics credentials below.
Confirm your username, share a bit about yourself, Once your account has been approved by our admins then you're ready to explore and connect .
Free trial account? No problem. Log in with your trial credentials to join. No free trial account? No problem! Register here
Already a member? Hi and welcome back! We're glad you're here 🙂
You will see the Qualtrics login page briefly before being taken to the Experience Community
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
