Hi. I have a survey that is going to need to have certain lists of response options customized based on geography. We are going to ask for zip code, but these zip codes correspond to one (or in some cases two or three) service areas. I want to make a custom variable that assigns these service area values based on zip code. We will then use those region codes to execute the hide row logic later on that will customize the lists they see based on where they live. It will also give us a way to more easily track the number of responses from each area. This is so easy to do in the program we have used in the past, and we used it all the time, so I really need to be able to make these custom variables and use them within the survey! But I was told this could only be handled through Java script in SG.
So immediately following zip code, I have a hidden page with a checkbox set up with all the service areas (which I will just call “area”)
So I need some direction as to what Java commands to use to basically tell it:
Check the box for Area option C if zip=11111, 22222, or 33333
Check the boxfor Area option D if zip=11111, 44444, or 55555
I hope this makes sense!
I would try to avoid using custom scripts if possible. I do not know how you are planning to distribute your survey links. But if it possible to send custom links to your regions, I would look into using URL variables (https://help.surveygizmo.com/help/using-url-variables-in-surveys). Use a different variable for each region and then use that to trigger the logic conditions within the survey.
If this is not possible and you have to use a custom script, I recommend the following:
You will have to create a hidden question that will receive the regional code you are going to use within the survey.
The script itself is very simple and uses just the sgapiGetValue and sgapiSetValue functions. There are examples of how these functions are used in the Developer documentation The following is a rough sketch of the script in pseudo-code:
//the question id of the zip code question is 24
if xzip >18999 and <20000
//the question id of the hidden service region question is 25
I would also recommend that you create a one-two page test survey to help you develop your code. The survey should consist of just the questions you will need to make sure that the script is running correctly. Once you are sure that you have a good working script you can copy/paste it over to your main survey.
If this is your first time writing code you will find this to be a frustrating, but ultimately rewarding experience. Once you have conquered this problem it will open your eyes to other possibilities for customizations. Good luck!