O'Reilly logo

Google Script: Enterprise Application Essentials by James Ferreira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix A. UI Element Examples

Boxes

Check Box

The check box: who knows where they came from, but how could we possibly live without them? A check box is a yes/no type of element that stands on its own, unlike radio buttons, which look similar but only allow a single selection. You can have 1 or 100 check boxes on a page and each has its own value.

In this example, you will check a box and click Submit. Typically you would have several elements on a page along with check boxes, and you will need to read if the box is checked along with other information.

Reference: http://code.google.com/googleapps/appsscript/class_checkbox.html

function checkBox(){ var mydoc = SpreadsheetApp.getActiveSpreadsheet(); var app = UiApp.createApplication().setTitle('Check Box Example'); //A button to take care of the submission. var mybutton = app.createButton('Submit'); //using setName will give you the ability to get the value var myCheckBox = app.createCheckBox().setName('myCheckBox'); //A label will be used to give feedback on the value of the checkBox var infoLabel = app.createLabel('Check the box and click submit').setId('infoLabel'); //the next 3 lines add a handler to preform a function when the submit button is clicked var handler = app.createServerClickHandler('changeMe_'); handler.addCallbackElement(myCheckBox); mybutton.addClickHandler(handler); //put everything in the UI app.add(myCheckBox); app.add(mybutton); app.add(infoLabel); mydoc.show(app); } function changeMe_(e){ var app = UiApp.getActiveApplication(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required