Help, Zip Code Checker | XM Community
Skip to main content
Solved

Help, Zip Code Checker


Renato
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.

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 original

5 replies

AnthonyR
Level 4 ●●●●
Forum|alt.badge.img+7
  • Level 4 ●●●●
  • 306 replies
  • August 27, 2018
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/

Renato
  • Author
  • 2 replies
  • August 27, 2018
How can I code that in Q2?
or does it just have to be in a subsequent question?

AnthonyR
Level 4 ●●●●
Forum|alt.badge.img+7
  • Level 4 ●●●●
  • 306 replies
  • Answer
  • August 27, 2018
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

Renato
  • Author
  • 2 replies
  • August 27, 2018
Thank you very much, Anthony! Very Helpful!

PhilipMoore
Level 2 ●●
Forum|alt.badge.img+11
  • Level 2 ●●
  • 16 replies
  • October 11, 2024

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


Leave a Reply