Matching a numeric response to a list

I have a question (Q1) asking respondents for their 5 digit zipcode (I set this up as an Open Ended with some javascript to make sure it only contains numbers. This is to allow for zipcodes beginning with a 0).

I have a list with 265 zipcodes in it and I need to set a skip if their  response at Q1 matches any of the zipcodes in that list.  I'm a bit foggy on the easiest way to accomplish this.  Any help?
asked Apr 26, 2013 by Jay Bronze (3,642 points)
The provided solutions are great.  I had also set up a quota question in which the first quota I defined using a series of "or" statements (i.e. Q1="55420" or Q1="34614", etc.).  Which wasn't too bad to do as I used Excel to get the phrasing I needed in different columns with the zipcode list and then concatenated the text into a string I could paste into my logic.  Then the second quota was set to always qualify.  Now in my skip logic I was just able to use that quota question.

2 Answers

0 votes
Firstly, it is important you control the validation of the zipcode with JavaScript as you mentioned. Also, make sure the range of zipcodes is controlled too.

We can create a constructed list which adds any matched zipcodes to the constructed list below. Here's the code (let's call this contructed list ZipCodeMatchList) ...

Begin Unverified Perl

my $i=1;

for ($i=1; $i<=265; $i++)
 {
  if (VALUE("Q1")==LISTLABEL("ZipCodeList",$i))
   {
    ADD("ZipCodeList",$i);
   }
 }

End Unverified 


I have assumed your 265 zipcodes are in a list called ZipCodeList.

With regards to the skip, use the condition  ...

ListLength(ZipCodeMatchList)=0

If ZipCodeMatchList has no codes added, that means there were no matches.

I have tested this. Works a treat.
answered Apr 27, 2013 by Paul Moon Silver (9,276 points)
Thanks much Paul.  Simple but effective! It was the matching to the ListLabel that eluded me.  Perfect.
As long as you did not have to manually type out each zipcode, this solution was simple. A quick copy and paste into a parent list and my code into a constructed list and you were up and running with a solution. Same goes with Bahadir's solution, nice and neat providing no manual typing of zipcodes.
0 votes
I've used the code below directly in SKIP logic with success, I don't think it is the easiest way, but your choice :)
Begin Unverified Perl
my $criterialist = "001,002,086,087,007,480,277,008,159,033,035,060,166,153,092,167,036,131,020,021,022,024,168,154,026," ;
my $criteria = VALUE("Q1") . ","; 
if (index($criterialist,$criteria) == -1) {return "TRUE";}
End Unverified


The logical problem here is that skip logic treats any non-null response from here as true.. even if you were to write return false above, it would activate the skip
answered Apr 27, 2013 by Bahadir Ozkurt Gold (10,016 points)
Thanks Bahadir! I always love seeing different solutions to keep in the arsenal.
...