Tuesday 11 April 2023

Google Form Checkbox responses

The following Google Apps Script is an example of one way to get the responses from a Checkbox-type question on a Google Form and how you might go about differentiating them.

This came up for a project I was working on where I need to put a Yes/No value into 3 separate Google Sheet cells based on 3 options in a question. The slight challenge is that all of the responses come out as a single array for this question, containing the strings of the values that have been ticked only.

Get all checkbox responses from a Form

The Code

You will need to create a 'form submit' trigger in order to connect the Apps Script code with the Google Form and capture responses when it has been submitted.

Next we get an object containing the question names and values from the form submission, along with our specific question:

// get all Form responses
var formValues = e.namedValues;

// get response to specific question
var pizzaTopping = formValues["Favourite Pizza Topping"][0];

From here what we will use is the JavaScript method 'includes()' to look through the array for a specific value. Combined with an 'if' to perform an action depending on if the value has been found - which is where we could perform additional actions such as updating other cell values, etc:

if (pizzaTopping.includes("Chicken")) {

  console.log("Likes Spicy Chicken");

} else {

  console.log("Does not like Spicy Chicken");




Google Form Checkbox responses folder download (please use 'File' > 'Make a copy' for your own version).

No comments:

Post a Comment