I have successfully managed to populate the Google Apps Script listbox based on the previous listbox selection for two options, but unfortunately, I am encountering issues

Struggling to set up 3 list boxes that populate based on each other? At the moment, I have one list box fetching data from a spreadsheet. Could someone assist me in configuring it so that the second list box populates based on the first, and a third list box populates based on the second one? Below is the code snippet:

function doGet(e){
  var app = UiApp.createApplication();
  var mainPage = app.createVerticalPanel().setId('mainPage');
  var dataItemsLB = app.createListBox().setId('dataItemsLB').setName('dataItemsLB'); 
  var dataItemsLbl = app.createLabel('Data Items'); 
  dataItems(dataItemsLB);
  mainPage.add(dataItemsLB);
  app.add(mainPage);
  return app;
  }


  function dataItems(listbox){
  var app = UiApp.getActiveApplication();
  var ss = SpreadsheetApp.openById('0AhraBJOts4V3dDhYbERTR0hFNUtNdEhZd2c4OElpY0E');
  var list = ss.getSheetByName('dataItems');
  var values = list.getRange(1,1,ss.getLastRow(),1).getValues();
  for (var i in values){
  listbox.addItem(values[i][0].toString());
  }
  return app;
  }

The above code snippet only covers populating one list box. However, starting from the basics will help me grasp the concept better as you explain. Appreciate any guidance!

Answer №1

Answer provided in the community:

function submitData(e){
  var app = UiApp.createApplication();
  var mainPanel = app.createVerticalPanel().setId('mainPanel');
  var dropdown1 = app.createListBox().setId('dropdown1').setName('dropdown1'); // create a basic list box
  var dropdown2 = app.createListBox().setId('dropdown2').setName('dropdown2'); // create a basic list box
  var dropdown3 = app.createListBox().setId('dropdown3').setName('dropdown3'); // create a basic list box
  var label = app.createLabel('Dropdown Options'); 
  populateDropdown(dropdown1); // call the "populateDropdown" function to fill the list box

  // Create Server Handlers
  var serverHandler = app.createServerHandler("handleDropdownSelect");
  serverHandler.addCallbackElement(mainPanel);
  dropdown1.addChangeHandler(serverHandler);
  dropdown2.addChangeHandler(serverHandler);  

  mainPanel.add(dropdown1);
  mainPanel.add(dropdown2);
  mainPanel.add(dropdown3);
  app.add(mainPanel);

  return app;
}

function populateDropdown(dropdown){
  var app = UiApp.getActiveApplication();
  var ss = SpreadsheetApp.openById('0AhraBJOts4V3dDhYbERTR0hFNUtNdEhZd2c4OElpY0E');
  var sheet = ss.getSheetByName('DropdownOptions');
  var values = sheet.getRange(1,1,ss.getLastRow(),1).getValues();
  for (var i in values){
    dropdown.addItem(values[i][0].toString());
  }
  return app;
}

function handleDropdownSelect(e) {
  var app = UiApp.getActiveApplication();
  Logger.log(e);
  Logger.log("Dropdown changed: " + e.parameter.source);
  // check which dropdown has been changed:
  switch(e.parameter.source) {
    case "dropdown1":
      var dropdown2 = app.getElementById("dropdown2");
      dropdown2.addItem("Option A"); 
      dropdown2.addItem("Option B"); 
      dropdown2.addItem("Option C"); 
      break;
    case "dropdown2":
      var dropdown3 = app.getElementById("dropdown3");
      dropdown3.addItem("Option X"); 
      dropdown3.addItem("Option Y"); 
      dropdown3.addItem("Option Z"); 
      break;     
  }
  return app;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AngularJS textbox validation for numbers and required in repeating mode ensures that the user input is a

For more information, please visit the following link: https://plnkr.co/edit/9HbLMBUw0Q6mj7oyCahP?p=preview var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope) { $scope.NDCarray = [{val: '' ...

Transforming an array into key-value pairs where the keys are odd elements and the values are even elements

Is there a straightforward way to transform this initial array: [ "Bargain", "deal", "Consistent", "Steady; regular", "Accurately", "a thing bought or offered for sale much more cheaply than is usual or expected.", "Charge", "demand (an am ...

Unable to get angular button hold loop to work properly

My goal is to create a button that can be pressed once to execute a single command, but also has the capability to hold the button down and execute the command multiple times while still holding it. I am working with AngularJs (though I don't believe ...

Showing dynamic content retrieved from MongoDB in a list based on the user's selected option value

Implementing a feature to display MongoDB documents conditionally on a webpage is my current goal. The idea is for the user to choose an option from a select element, which will then filter the displayed documents based on that selection. For instance, if ...

When using v-select to search for items, the selected items mysteriously vanish from

I recently worked on a project where I encountered a similar situation to the one showcased in this CodePen. Here is the link to the specific CodePen One issue I faced was that the selected items would disappear when performing an invalid search. After i ...

Having trouble creating a table using a JSON object in AngularJS

Click here to view the converted JSON object Please pay close attention to my question Hello, in the code below I am attempting to convert XML data into a JSON object. With this converted JSON object, I am aiming to create a table using AngularJS. The is ...

Create static HTML files using an Express server

Recently, I developed a nodejs web project using express-js and ejs. However, upon further reflection, it occurred to me that hosting it as static html files on Netlify might be more cost-effective than running it as a nodejs app on Heroku. Since the data ...

Best practice for resetting jquery datatables for proper functioning

A user on Stack Overflow was seeking a solution for working with DataTables.js and a variable number of columns. The provided solution can be found here: http://jsfiddle.net/gss4a17t/. It's worth noting that this solution relies on a deprecated funct ...

What is the reason for and <br> not functioning in a string?

I am encountering an issue when attempting to print the content of an object. Some of the properties within the object contain tags, making it challenging to create new elements in JavaScript without knowing which properties will include these tags. How ...

Combine the array elements by date in Angular, ensuring no duplicates are present

How can array data be merged based on the date while avoiding duplicates? See the code snippet below: [ { date: [ '2019-12-02 08:00:00', '2019-12-03 08:00:00' ], upload:["47.93", "47.46", "47.40", "47.29" ], download: ["43.90", ...

Navigating between routes with React-router v4: A beginner's guide

There seems to be an issue with the routing functionality in my project. Currently, only the first component, Cloud, is being rendered on the / route. However, when I try to add other routes, they don't seem to work as expected. import React from &a ...

Is the Date Epoch a reliable form of unique identification?

Currently, I'm developing a Node API and encountered a situation where I need to create a unique 15-digit random number for a model without using autoincrement. The challenge is to ensure that the generated number is not trivial. I am hesitant about ...

Unleash the Power of Your Webpage: Instantly Engage Full

Is there a way to automatically make a webpage open in full screen mode as soon as it is loaded? Here's what I currently have: var elem = document.documentElement; function openFullscreen() { if (elem.requestFullscreen) { elem.requestFull ...

Synchronous async routes in Node Express

My express server requires fetching data from multiple external sources for each request, with the logic separated into various routers (some of which are not under my control). These routers operate independently, eliminating the need for one to wait on ...

What is the process for retrieving information from a retail outlet?

How can I retrieve data from the Vuex store using Vue.js? Below is my code: Vue.use(Vuex); export default new Vuex.Store({ modules: { data } }) data.js import axios from 'axios'; const state = { data: '' }; cons ...

React does not allow objects as child elements. Instead, render a collection of children by using an array

Encountering an error with this React class Error: Objects are not valid as a React child (found: object with keys {_id, name}). If you meant to render a collection of children, use an array instead. Is there anything amiss here? I am passing the movies ...

Managing Pop-Ups when browsing on Internet Explorer

I've been working on an Excel VBA macro that automates several tasks on the Medicare website. The macro opens IE, logs in, compares claims, and alerts me to any differences found. However, I've encountered a problem during the log-in step, specif ...

Troubles arise when trying to convert a schema using Normalizr

Is there a way to efficiently convert a JSON array containing travel expenses into a format that allows for easy retrieval of expenses by travelExpenseId and tripId? [ { "travelExpenseId":11, "tripId":2, "paymentPurpose":"some payment ...

Utilizing a combination of MVC, jQuery, and Ajax to ensure that JavaScript is fully loaded before proceeding

Utilizing ASP.NET MVC and jQuery, I am loading a PartialView via Ajax which has its own accompanying JavaScript file. Upon successful retrieval of the html content, it is inserted into the DOM. However, there can be a delay between the insertion and the ex ...

Tips for automatically closing all other divs when one is opened

I have multiple divs structured like this: <div id="income"> <h5 onclick="toggle_visibility('incometoggle');">INCOME</h5> <div id="incometoggle"> <h6>Income Total</h6> </div> </div> <d ...