[英]Call checkbox value if checked from html file in javascript function
我有两个文件:google脚本中的myPage.html和myCode.gs。 我已经将html文件部署为Web应用程序,并且我已经(在帮助下)弄清楚了如何使“提交”按钮的onclick事件触发myCode.gs文件中的emailTech函数。 我还能够将html文件中文本框中的值插入到onClick事件调用的电子邮件中。
我还有两个复选框,如果选中,我希望将其值输入到由onClick事件触发的电子邮件中。 我在html文件的脚本阶段和emailTech函数中都尝试了各种版本的“如果选中,然后”语句,但是似乎都不起作用。 有什么建议么?
myPage.html文件:
<head>
<title>Test Page</title>
</head>
<body>
<form>
<input type="text" value=" " name="techEmail" />
<input type="checkbox" name="checkone" value="checkone" />Checkone
<input type="checkbox" name="checktow" value="checktwo" />Checktwo
<input type="button" onClick="formSubmit()" value="Submit" />
</form>
</body>
<script type="text/javascript">
function formSubmit() {
google.script.run.emailTech(document.forms[0]);
}
</script>
myCode.gs文件:
function doGet() {
return HtmlService.createHtmlOutputFromFile('myPage');
}
function emailTech(form){
//I want something along the lines of:
//if form.checkone == "checked"{
//var checkone = "checkone"
//}
//if form.checktwo == "checked"{
//var checktwo = "checktwo"
//}
var nameBox = form.techEmail;
var message = "This is the text box value" + nameBox + checkone + checktwo;
MailApp.sendEmail("email@somewhere.com", "This is the subject", message );
}
另外,单击提交按钮时,是否可以清除文本框和复选框? 我不想使用单独的重置按钮,如果可能的话,我希望通过单击来重置并发送电子邮件。 提前致谢!
复选框输入不应位于自动关闭标签中。 (以/>
结尾的那个。)您还需要将value
设置与处理程序中要查找的value
(“选中”)对齐。 像这样更改您的html:
<input type="checkbox" name="checkone" value="checked" >Checkone
<input type="checkbox" name="checktow" value="checked" >Checktwo
现在,在服务器端处理程序中,您只需检查'checkone'和/或'checktwo'的存在,因为它们只有在被选中时才会在事件中传递。 您也可以按照计划检查该值。
只需从您的“愿望”中删除注释,修复语法,就可以了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.