google apps script - fill listbox when I select another listbox -


sorry code, try simplify in example explication. information of listbox depend of select in other listbox, can´t work. sorry bad english.

here create form;

function doget(){   var app = uiapp.createapplication().settitle('request form');   var flow = app.createflowpanel().setstyleattribute("textalign", "center").setwidth("900px");        var lreason = app.createlabel('select reason :');       var listreason= app.createlistbox().setname("listreason").additem("").additem("salud").additem("motivo personal");       var lfactor = app.createlabel('select factor :');       var listfactor= app.createlistbox().setname("listfactor").additem("select reason first").setid(listfactor);     var handlerr = app.createservervaluechangehandler('factors');   handlerr.addcallbackelement(flow);   listreason.addchangehandler(handlerr);      var test1 = app.createlabel('nada');     var gridd = app.creategrid(4,5);        gridd.setwidget(2,0,lreason)       .setwidget(2,1,listreason)       .setwidget(2,3,lfactor)       .setwidget(2,4,listfactor)       .setwidget(3,0,test1.setid('test1'));      flow.add(gridd);   app.add(flow);     return app;   } 

//////////////////here create function fill other listbox

function factors(e){ var app=uiapp.getactiveapplication();   var var1=e.parameter.listreason; app.getelementbyid('test1').settext(var1);    switch (var1) {      case "salud":  var ss = spreadsheetapp.openbyid('1pbayt_tb84e3wkhb-h5tvzjolx04f-uq-iom8o3kvhs'); var list = ss.getsheetbyname('salud');   var lastrow = list.getlastrow();  var templ = app.createlistbox();   var values = list.getrange(2,1,lastrow-1,1).getvalues(); (var in values){ templ.additem(values[i][0].tostring()); } app.getelementbyid('listfactor').additem(templ);    break;      case "motivo escolar":  var ss = spreadsheetapp.openbyid('1pbayt_tb84e3wkhb-h5tvzjolx04f-uq-iom8o3kvhs'); var list = ss.getsheetbyname('motivoescolar');   var lastrow = list.getlastrow(); var templ = app.createlistbox();    var values = list.getrange(2,1,lastrow-1,1).getvalues(); (var in values){ templ.additem(values[i][0].tostring()); } app.getelementbyid('listfactor').additem(templ);   break;      default:   app.getelementbyid('test1').settext("empty");        break  }     return app;  } 

this code use wrong (see comments in code):

for (var in values){ templ.additem(values[i][0].tostring()); } app.getelementbyid('listfactor').additem(templ);// can not add litbox item in listbox 

you should add 1 item after other in loop... move code :

for (var in values){ //templ.additem(values[i][0].tostring()); // new list box useless since populate existing 1 app.getelementbyid('listfactor').additem(values[i][0].tostring()); } 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -