Lua Scripting Resources

Important Update to Custom Scripting

SurveyGizmo's CustomScript Action now supports the LUA programming language.


Legacy Custom Scripting Language Deprecation Plans 

  1. New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
  2. As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
  3. In the long term, Legacy Custom Scripting Actions will be switched to read-only. Read-only scripts will continue to function; you will just be prevented from editing. The exact date on this is to be determined; we will send notifications well ahead of time.


 Go to our Legacy Scripting Documentation.

While SurveyGizmo is one of the most flexible survey tools around, we get requests for customizations that are not available out of the box. This is where JavaScript and Custom Scripting can save the day. If you have scripting chops you can use the JavaScript action or the Custom Scripting action to achieve the survey of your dreams.


[article("bodfy")]

Often survey builders wish to set the maximum answers a respondent can provide to a checkbox question dynamically based on the value entered in a previous Textbox question. You can achieve this, both for Checkbox questions on the same page and later pages, with a little bit of JavaScript. 

See it in action in an example survey!

OR

Add a survey with this script and setup to your account!

To get started, create a Textbox question where you will collect the value that you will use in the maximum answers validation for the Checkbox question. Then create your Checkbox question. The questions can be on the same page or on different pages. 

Add a JavaScript action to the page with your Checkbox question. Copy and paste one of the below scripts; there is one for when the Textbox and Checkbox questions are on the same page and one for when they are on different pages. 

The script for when Textbox and Checkbox questions are on the same page:

$(document).ready(function(){
 
  var maxans;
 
  $(".max :text").blur(function(){
    maxans = $(this).val();
  });
 
  $(".checkboxQuestion").change(function(){
    var checked = $(".checkboxQuestion :checkbox:checked").length;
    if (checked == maxans) {
      $(".checkboxQuestion :checkbox:not(:checked)").attr("disabled",true);
    }
   
    if (checked < maxans) {
      $(".checkboxQuestion :checkbox").attr("disabled",false);
    }
  });
});

Once you have added the JavaScript to the page with your Checkbox question you need to add the CSS Class Names to each of the questions you wish to apply this script to. checkboxQuestion should be added to the Checkbox question and max should be added to the Textbox question. These classes should be added to the CSS Class Name field on the Layout tab of each question.

The script for when the Checkbox question is on a later page:

$(document).ready(function(){
 
  var maxans = '[question("value"), id="5"]';
 
  $(".checkboxQuestion").change(function(){
    var checked = $(".checkboxQuestion :checkbox:checked").length;
    if (checked == maxans) {
      $(".checkboxQuestion :checkbox:not(:checked)").attr("disabled",true);
    }
   
    if (checked < maxans) {
      $(".checkboxQuestion :checkbox").attr("disabled",false);
    }
  });
});

Once you have added the JavaScript to the page with your Checkbox question you will need to change the highlighted ID in the script to the ID of your checkbox question. Learn How to Find Question IDs.