![](/img/trans.png)
[英]Google apps script: Form Submit trigger doesn't execute script properly, and script only works with a manual execution
[英]Google Apps Script - Form inputs not submitting properly
<form id="colours" onsubmit="doSomething()">
<label for="startcolour" style="font-family:arial">Start:</label>
<input type="color" name="startcolour" id="startcolour" value="#123456">
<label for="endcolour" style="font-family:arial">End:</label>
<input type="color" name="endcolour" id="endcolour" value="#abcdef"><br><br>
<br>
<input type="submit" value="Submit">
</form>
<script>
var startcolour = document.getElementById("startcolour").value;
var endcolour = document.getElementById("endcolour").value;
function doSomething() {
google.script.run.withFailureHandler(function(error) {
console.log("error")
console.log(error.message)
}).withSuccessHandler(function(result) {
console.log("done!")
}).test(startcolour);
}
</script>
我有一个 Google Apps Script HTML 侧边栏。 这是 HTML 侧边栏的一些代码。 当我输入颜色并按“提交”时,我希望它以提交的 startcolour 值作为输入运行 test() 函数。 但是,它使用默认值“#123456”运行,而不是用户提交的值。 我该如何解决?
问题是您正在从 doSomething 函数外部定义“startcolour”和“endcolour”变量,因此当调用该函数时,它使用页面加载时定义的值,而不是您可以使用的值定义何时提交表单。
解决方案是在 doSomething 函数中定义变量“startcolour”和“endcolour”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.