I want to use "Qualtrics.SurveyEngine.addOnUnload" to set embedded data with Javascript. I want to use "addOnUnload," though, so I can compare 2 values from questions in this block. Here is my script. The console.log returns the values I expect to see, but the embedded data is not set.
Note: In my survey flow, I have a "Set Embedded Data" block with the defined data before the block containing this script. I tried putting it after the block. That didn't help.
//set zip code data
var zipArray = [
"84003",
"84004",
"84005",
"84116"
]
var var1 = jQuery("#QID10").find(".InputText").val();
var placeholder = jQuery.inArray( var1, zipArray );
var saltLakeZip = ''; // extra step but helps with console.log troubleshooting.
if (placeholder != -1) {
saltLakeZip = 'yep';
Qualtrics.SurveyEngine.setEmbeddedData( 'saltLakeCityZip', saltLakeZip ); //Qualtrics embedded data
} else {
saltLakeZip = 'nope';
Qualtrics.SurveyEngine.setEmbeddedData( 'saltLakeCityZip', saltLakeZip ); //Qualtrics embedded data
}
console.log('saltLakeZip = ' + saltLakeZip)
//set ticket data
var var2 = jQuery("#QID18").find(".InputText").val();
var theID = '';
if (var2.indexOf("Salt Lake City") !== -1 && saltLakeZip == 'yep') {
theID = 'SLC';
} else {
theID = 'AAA'
}
Qualtrics.SurveyEngine.setEmbeddedData( 'ticketID', theID ); //Qualtrics embedded data
console.log('ticket01 = ' + theID);
//console.log returns the correct values, but qualtics won't set teh embedded data.
If I use "Qualtrics.SurveyEngine.addOnload" with a blur on each question field, then the Javascript will set the embedded data, but that doesn't work for me because I want to compare the two values AFTER the user is done making changes and clicks the "Next" button.
Use Javascript to set Embedded Data with addOnUnload
Best answer by ahmedA
AddonUnload is triggered when the page is unloaded, not when it starts unloading. So there are no values for your code to store.
You could look at addonPageSubmit or use the click on the next button as the trigger.
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.
