Dependent dropdown list in Google Forms

In this post, I demonstrate how to create a dependent drop-down list in a Google Web App using Google Apps Script on Google Sheets.

How to Video:

Video Notes:

  • Legacy Apps Script Editor Used in Video
  • Apps Script (Script Editor) is now located under tab Extensions instead of Tools on Google Sheets

Code in Video:

function doGet(e) { var htmlOutput = HtmlService.createTemplateFromFile('DependentSelect'); var colors = getColors(); htmlOutput.message = ''; htmlOutput.colors = colors; return htmlOutput.evaluate(); } function doPost(e) { Logger.log(JSON.stringify(e)); var name = e.parameters.name.toString(); var color = e.parameters.color.toString(); var fruit = e.parameters.fruit.toString(); AddRecord(name, color, fruit); var htmlOutput = HtmlService.createTemplateFromFile('DependentSelect'); var colors = getColors(); htmlOutput.message = 'Record Added'; htmlOutput.colors = colors; return htmlOutput.evaluate(); } function getColors() { var ss= SpreadsheetApp.getActiveSpreadsheet(); var lovSheet = ss.getSheetByName("LOV"); var getLastRow = lovSheet.getLastRow(); var return_array = []; for(var i = 2; i <= getLastRow; i++) { if(return_array.indexOf(lovSheet.getRange(i, 1).getValue()) === -1) { return_array.push(lovSheet.getRange(i, 1).getValue()); } } return return_array; } function getFruits(color) { var ss= SpreadsheetApp.getActiveSpreadsheet(); var lovSheet = ss.getSheetByName("LOV"); var getLastRow = lovSheet.getLastRow(); var return_array = []; for(var i = 2; i <= getLastRow; i++) { if(lovSheet.getRange(i, 1).getValue() === color) { return_array.push(lovSheet.getRange(i, 2).getValue()); } } return return_array; } function AddRecord(name, color, fruit) { var url = ''; //URL OF GOOGLE SHEET; var ss= SpreadsheetApp.openByUrl(url); var dataSheet = ss.getSheetByName("DATA"); dataSheet.appendRow([name, color, fruit, new Date()]); } function getUrl() { var url = ScriptApp.getService().getUrl(); return url; }

Web App Dependent Drop Down










Dependent dropdown list in Google Forms
Dependent dropdown list in Google Forms
How to Deploy a Google Web App - In this post, I demonstrate how to deploy a Google Web App. I cover all the settings that are involved in deploying a web app.
Dependent dropdown list in Google Forms
Dependent dropdown list in Google Forms
Create Multi-Select Dropdown in Web App on Google Sheets - In this post, I demonstrate how to use a multi-select dropdown in a Web App on Google Sheets. This will in turn store the multiple values in a cell on Google Sheets.
Dependent dropdown list in Google Forms
Dependent dropdown list in Google Forms
Create File Loader Google Web App to Google Drive - In this post, I demonstrate how to create a File Loader Google Web App to Google Drive on Google Sheets. It works with such files as PNG, JPG, DOC, XLS, PDF, and many more.
Dependent dropdown list in Google Forms
Dependent dropdown list in Google Forms
How to Filter Google Sheet in Google Web App - In this post, I demonstrate how to Filter a Google Sheet in a Google Web Application using HTML and Google Apps Script.
Dependent dropdown list in Google Forms
Dependent dropdown list in Google Forms
How to Display Google Sheet in Web App - In this post, I demonstrate how to display a Google Sheet Table in a Web App using Google Apps Script.