【发布时间】:2021-04-04 19:52:12
【问题描述】:
我想访问 Google Script 中选定选项的值。
我得到了这个 HTML 表单。有一个选项。
<form id="invoice" _lpchecked="1">
<label for="company">company:</label><br>
<input type="text" id="company" name="company" value=""><br>
<br>
<label for="user">created:</label>
<select id="user">
<option value="Radek">Radek</option>
<option value="Lucka">Lucka</option>
</select>
<input type="submit" value="send" onclick="event.preventDefault(); sendForm(this);">
</form>
表单被发送到 Google Script
function sendForm(theForm){
//var invoice = document.getElementById("invoice");
//invoice.user = document.getElementById("user").value;
google.script.run.withSuccessHandler(formSent)
.processForm(document.getElementById("invoice"));
}
然后在 GAS 中我可以访问表单数据。通过记录表单数据,我发现该选项没有密钥。在form 对象中存在正确的值,但键为空。可以帮助获得 GAS 中的选择选项吗?我尝试将user 键添加到表单数据,但没有成功。
function processForm(form){
var result = "OK";
var data = [(new Date()).toLocaleString("cs-CZ"),
form.company,
form.user]
for (var key in form) {
Logger.log('the key is: ' + key);
Logger.log('the value is: ' + form[key]);
};
saveInvoiceData(data); // saves data to Google Sheets
return result;
}
有没有办法在 IDE 中使用断点进行调试?
【问题讨论】:
标签: google-apps-script html-select