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(); ...

Get Google Script: Enterprise Application Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.