In the JS logic, you would set the embedded data then based on the embedded data you determine the subsequent branching.
Qualtrics JavaScript Question API - Qualtrics Question API
pogi
Thank you for taking the time to read my post. That helps, but I'm still not getting it. I was hoping someone could provide some sample Javascript. For example, my zip code field is a text field. Do I need to add an onChange trigger or similar?
I think this is a start, but I don't know how to get the value of the text field.
var q = jQuery("#"+this.questionId);
q.find(".InputText").on("blur", function(e) {
console.log(what goes here?);
});
After reading posts from pogi and TomG , I came up with the following. This gets the job done, but I wonder if there is a more concise or elegant way to make it work.
The setEmbeddedData part comes from AnthonyR on this post.
I added the script to: Qualtrics.SurveyEngine.addOnload(function() {
//I want to find out if the user enters a zip code that matches one of my Salt Lake City codes in an array.
var zipArray = [
"84003",
"84004",
"84005",
"84010",
"84664"
]
var q = jQuery("#"+this.questionId);
var theZip = null; //what did the user enter? changes on blur
var saltLakeZip = false; //is this an SLC zip?
// when the input text blurs, do something
q.find(".InputText").on("blur", function(e) {
theZip = q.find(".InputText").val();
//console.log("theZip = " + theZip);
var zipPlaceholder = jQuery.inArray( theZip, zipArray ); //is theZip in my array? For example, 84003 is there so it won't result in "-1"
if (zipPlaceholder != -1) {
//console.log('there was a match');
saltLakeZip = true;
Qualtrics.SurveyEngine.setEmbeddedData( 'saltLakeCityZip', "yes" ); //saltLakeCityZip is Qualtrics embedded data
} else {
saltLakeZip = false;
Qualtrics.SurveyEngine.setEmbeddedData( 'saltLakeCityZip', "no" ); //saltLakeCityZip is Qualtrics embedded data
}
//console.log("saltLakeZip = " + saltLakeZip);
});