Created
November 10, 2012 03:26
-
-
Save tetsunosuke/4049724 to your computer and use it in GitHub Desktop.
GoogleAppsScriptでチェックボックス の改造
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// global にしておく | |
var checkBoxArray = ['幼少期(0~6歳頃)', | |
'学童期(6~12歳頃)', | |
'青年期(12~25歳頃)', | |
'成人期(25~40歳頃)', | |
'中年期(40~65歳頃)', | |
'老年期(65歳~)']; | |
function doGet() { | |
var app = UiApp.createApplication(); | |
var checkboxpanel = app.createVerticalPanel(); | |
var handler = app.createServerHandler('checkChanged').addCallbackElement(checkboxpanel); | |
//チェックボックスを作成、選択された項目を表示するためのラベルの作成 | |
var checkboxContainer = app.createVerticalPanel(); | |
var infobox = app.createVerticalPanel(); | |
for (var i=0; i < checkBoxArray.length; i++) { | |
checkboxContainer.add(app.createCheckBox(checkBoxArray[i]).setName("age" + i).addClickHandler(handler)); | |
infobox.add(app.createLabel(checkBoxArray[i]).setId('info' + i).setVisible(false)); | |
} | |
//チェックボックス、ラベルをレイアウトパネルに追加 | |
checkboxpanel | |
.add(app.createHTML('<p>どの年代の出来事かを選択してください。(任意)</p>')) | |
.add(checkboxContainer) | |
.add(infobox); | |
app.add(checkboxpanel); | |
return app; | |
} | |
function checkChanged(e){ | |
var app = UiApp.getActiveApplication(); | |
for (var i=0; i < checkBoxArray.length; i++) { | |
// 飛んできたパラメータが"true"かどうかで表示非表示の切替 | |
app.getElementById("info" + i).setVisible(e.parameter["age" + i] === 'true'); | |
} | |
return app; | |
app.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment