Monday 15 April 2013

How to use a For loop to create Google Forms checkbox choices -


I have tried several iterations of the code below with limited success, logger commands appear properly, but the form After executing the order it does not seem to apply, the form only generates a non-defined checkbox.

Looking at this checkbox question several times with a few different question words, I'm trying to reduce the footprint of my code, and hopefully that's going to happen. More efficient

Here's the snippet of code I think is to fail:

  on storerangestart = 9901; Var Storerangeand = 9999; Page402_cbitem1.setTitle ('Are the stores allocated to this project?'); On page402array = 'page402_cbitem1.setChoices (for [\ N'; (I = storerangestart; I & lt; storerangeend; i ++) {var storerangecurrent = I + ""; page402array + = 'page402_cbitem1.createChoice (' + ' Storerangecurrent + '), \ N';} Page 402 He + = 'Page 402_cbitem1.createChoice (' + storerangeend + ') \ n]); '; Logger.log (page402array); Page402array (); After the text "itemprop =" text "> 

The logger is not showing you the order, so it is showing you a string. Your code is a string that looks like a text that contains code, but there is no way that the string Google Apps Script has any way to perform the contents directly.

You've got a good idea - you're just stuck trying to beat the wrong object type

Look at the definition of, then you can change it as a parameter Takes an array .. Example code may have thrown you because he created item elements in the .setChoices () method call

  item.setChoices ([item.createChoice ('Cats '), Item.createChoice (' dog ')]);   

You may feel the same result in this way:

  var option = []; // Create a new array of options options. Push (item.createChoice ('cats')); // Add 'Cats' option. Push (item.createChoice ('dog')); // Add 'Dogs' item. Sets option (option); // Set the array of options   

This sets the opportunity for the loop that you are thinking instead of creating a string of code, you can create different array of options for different object methods first And then call to specify that form as the option of your form item:

  var storerangestart = 9901; Var Storerangeand = 9999; Page402_cbitem1.setTitle ('Are the stores allocated to this project?'); Var page 402 Hey = []; (Var i = storerangestart; i & lt; storerangeend; i ++) for {var storerangecurrent = i + ""; Page 402 Hey Pat (page 402_cbitem1.createChoice); Logger.log (page 402); Page 402_cbitem1.setChoices (page 402);    

No comments:

Post a Comment