Help, Zip Code Checker | XM Community
Skip to main content
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.
If you want this to test the zip from Question 2 IN question 2, you can't get the value with piped text. Instead you want to check the text entry box on the page every time it is updated and use that to set your embedded data.



Also I imagine you will be seeing ".include is not a method" in your console, I believe the method you are looking for is "includes". If you don't know how to check your console for errors yet that is something that will be immensely helpful in your JavaScript endeavors.



https://developers.google.com/web/tools/chrome-devtools/console/
How can I code that in Q2?

or does it just have to be in a subsequent question?
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
Thank you very much, Anthony! Very Helpful!

If I use this script, how do I branch the Not Eligible in survey flow to terminate?


Leave a Reply