【发布时间】:2013-06-13 15:46:03
【问题描述】:
我使用 html 页面在 Google 脚本中创建了一个表单,然后调用了一个 javascript 函数 as documented here。当我运行应用程序时,表单加载得很好,但它不会执行脚本。我怎样才能做到这一点?
这是我正在尝试做的一个示例:
<html>
<!--Create Sign Out Form-->
<form id="signOut">
<div>
Destination:
<select name="destination">
<option value="lunch">Lunch</option>
<option value="meeting">Client Meeting</option>
<option value="vacation">Vacation</option>
<option value="sick">Out Sick</option>
<option value="personal">Personal</option>
<option value="home">Working from Home</option>
<option value="scedule">Reduced Schedule</option>
</select>
</div>
<div>
Supervisor:
<select name="supervisor" onselect="google.script.run.withUserObject(this.parentNode).populate(destination)"></select>
</div>
<div>
Start Date:
<input type="date" name="startDate" onselect="google.script.run.withUserObject(this.parentNode).SignOutLibrary.dateSelect()"/>
</div>
<div>
End Date:
<input type="date" name="endDate" onselect="google.script.run.withUserObject(this.parentNode).SignOutLibrary.dateSelect()"/>
</div>
<div>
Details:
<textarea type="text" name="details" style="width: 150px; height: 75px;"></textarea>
</div>
<div>
<input type="button" value="Submit"
onclick="google.script.run
.sendRequest(this.parentNode)"/>
</div>
</form>
</html>
以及它应该调用的脚本:
function doGet() {
// Uses html form
return HtmlService.createHtmlOutputFromFile('request_form');
}
SignOutLibrary:
function dateSelect() {
var app = UiApp.createApplication();
var handler = app.createServerHandler("change");
var date = app.createDatePicker().setPixelSize(150, 150).addValueChangeHandler(handler).setId("date");
app.add(date);
return app;
}
function change(eventInfo) {
var app = UiApp.getActiveApplication();
app.add(eventInfo.parameter.date);
return app;
}
【问题讨论】:
-
控制台有错误吗?
-
我还没遇到过。 (假设您正在谈论记录器,因为没有控制台:/)
-
我在文档中看到有一个onclick,有谁知道是否支持onselect?
-
另一个更新:我的提交按钮的 onclick 脚本不起作用?我什至尝试从头开始建立一个全新的库和表单,以确保这不是我选择的某个选项,它们仍然没有运行。
-
AFAIK google-form 适用于 Google 表单应用程序,不适用于使用 Google Apps 脚本的 HTML 服务创建的表单。应删除此标记。
标签: javascript html google-apps-script