Hi, everyone. Can someone please help me find the error of my ways?
I'm just trying to learn how to program a Zip Code screener with JS. I've searched some post and came up with this code to test:
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
var z=" ${q://QID2/ChoiceTextEntryValue}";
var b=[99501,99502,99503,99504].include(z);
if(b){
Qualtrics.SurveyEngine.setEmbeddedData("AUTH","Eligible");
}
else{
Qualtrics.SurveyEngine.setEmbeddedData("AUTH","Not Eligible");
}
});
This is in the Q2 JS Screen and it doesn't work. I'm using piped text in Q3 to show me the values:
${q://QID2/ChoiceTextEntryValue}
${e://Field/AUTH}
I also declared AUTH as Embedded Data in the survey flow prior to Q2.
Thanks in advance.
Solved
Help, Zip Code Checker
Best answer by AnthonyR
To get the value from the current question it would look SOMETHING like this (though this is not perfect and probably needs to be modified for your specific use:
Qualtrics.SurveyEngine.addOnReady(function()
{
let zipList = [99501,99502,99503,99504];
jQuery(this.questionContainer).find('.InputText').on('change keyup paste', function(){
let value = parseInt(jQuery(this).val());
if(zipList.includes(value)){
Qualtrics.SurveyEngine.setEmbeddedData("AUTH","Eligible");
}else{
Qualtrics.SurveyEngine.setEmbeddedData("AUTH","Not Eligible");
}
});
});
Demo QSF Attached
View originalQualtrics.SurveyEngine.addOnReady(function()
{
let zipList = [99501,99502,99503,99504];
jQuery(this.questionContainer).find('.InputText').on('change keyup paste', function(){
let value = parseInt(jQuery(this).val());
if(zipList.includes(value)){
Qualtrics.SurveyEngine.setEmbeddedData("AUTH","Eligible");
}else{
Qualtrics.SurveyEngine.setEmbeddedData("AUTH","Not Eligible");
}
});
});
Demo QSF Attached
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.