Sum a Column from a Custom Table

Important Update to Custom Scripting

SurveyGizmo's CustomScript Action now supports the LUA programming language. Visit our NEW Lua Scripting Resources!

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. The exact date on this is to be determined; we will send notifications well ahead of time.

Ever needed to sum the input to a textbox column on a Custom Table?*

This script is increadibly easy to add to your survey. The output is displayed to the respondent below the Custom Table.

Check it out in an example survey!

Put the script to work!

1.  Add a custom table question to your survey. Include a Textbox question as one of the column headers.

2. Click Add New Action, select JavaScript. Copy and paste the code below into the action:

$(document).ready(function(){
  
  //change this to your column header (case sensitive)
  var columnHeader = "Hours";
  var totalMessage = "Your total hours are:";
  
  
  //don't change below here!
  $("input[title='" + columnHeader + "']").last().after("<br><br>" + totalMessage + " <span class='total'>0</span>");
  
  $("input[title='" + columnHeader + "']").blur(function(){
    var sum = 0;
    $("input[title='" + columnHeader + "']").each(function(){
      var each = $(this).val()*1;
      console.log(each);
      sum += each;
      $(".total").text(sum);
    });
  });
});

3. Customize the variables. You will need to change "Hours" to the name of the column header for the Textbox Column in the Custom Table question. and "Your total hours are:" to the message you wish to display below the column.

4. Save and test the script.

*This script does not record the summed value for reference later.

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 SurveyGizmo features and functionality ideas that might meet your customization. Beyond this, you might want to consult with someone on our Programming Services Team; these folks might have the scripting chops to help you to achieve what you are looking for!