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);
});