The Continuous Sum question is a very popular question, particularly with our market researchers. Often survey designers are looking to make sure that the continuous sum total matches another value that the respondent entered. In this tutorial, we share a script for dynamically defining the maximum total value for a continuous sum question from an answer to a previous question.
Check it out in an example survey!
OR
Add this survey to your account!
Features Used to Implement Solution
We'll be using the following Alchemer features and LUA functions in this workaround:
- A Textbox, Slider, or Textbox List Question as the source question
- Continuous Sum Question
- getvalue
- isarray
- setquestionproperty
- jumptopage
The Script
This script will set the Max Total property of a continuous sum question to the value entered in a specified textbox list row, textbox, or slider.
The below script and associated Continuous Sum question must be added to a survey page after the textbox list row, textbox, or slider from which that value is pulled.
--Setting the max value of a continuous sum question dynamically
--The four variables directly below will need to be customized sourceID = 2 -- textbox list source QID targetID = 3 -- continuous sum target QID next_pageID = 2 -- pageID of the next page to jump to if the respondent has input zero hrs source_option_sku = 10002 -- option SKU for the TV hours option from textbox list source_value = getvalue(sourceID) -- values of source textbox list question property = 'max_total' if(isarray(source_value)) then setquestionproperty(targetID, property, source_value[source_option_sku]) if(source_value[source_option_sku] == 0) then jumptopage(next_pageID) end else setquestionproperty(targetID, property, source_value) if((source_value == 0)) then jumptopage(next_pageID) end end
Required Customizations
In the script above you will need to customize the below variables (first four variables in the above script) in order to make the script work the way you'd like.
- sourceID - This is the source question you wish to pull from to set the Continuous Sum question max total.
- targetID - The target Continuous sum question whose max total value you wish to set.
- next_pageID - pageID of the next page to jump to if the respondent enters zero in the source.
- source_option_sku - If source question is a Textbox List the option SKU for the row you wish to pull from must be specified. Not sure how to find your option SKU? Check out our How To Find IDs document! If your source is a Textbox or Slider question set
source_option_sku=0.
Scripting and Other Custom Solutions
We’re always happy to help you debug any documented script that is used as is. That said, we do not have the resources to write scripts on demand or to debug a customized script.
If you have customization ideas that you haven't figured out how to tackle, we're happy to be a sounding board for Alchemer features and functionality ideas that might meet your needs. Beyond this, check out our Professional Services; these folks have the scripting chops to help you to achieve what you are looking for!