1 回答
TA贡献1772条经验 获得超5个赞
我使用隐藏元素来区分它们。
ah1.html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function processForm(form) {
console.log(form);
google.script.run
.withSuccessHandler(function(obj){
console.log(obj);
document.getElementById("eml" + obj.number).value="";
document.getElementById("sub" + obj.number).value="";
document.getElementById("msg" + obj.number).value="";
//document.getElementById("ret" + obj.number).innerHTML=obj.msg;
})
.processForm(form);
}
console.log('My Code');
</script>
</head>
<body>
<form name="form1">
<input type="text" name="email" id="eml1" placeholder="Enter Email" />
<input type="text" name='subject' id="sub1" placeholder="Enter Subject" />
<textarea rows="4" name="message" cols="30" id="msg1" placeholder="Enter Message"></textarea>
<input type="hidden" name="number" value="1" />
<input type="button" value="Submit" onClick="processForm(this.parentNode);" />
</form>
<div id="ret1"></div>
<form name="form2">
<input type="text" name="email" id="eml2" placeholder="Enter Email" />
<input type="text" name="subject" id="sub2" placeholder="Enter Subject"/>
<textarea rows="4" name="message" cols="30" id="msg2" placeholder="Enter Message"></textarea>
<input type="hidden" name="number" value="2" />
<input type="button" value="Submit" onClick="processForm(this.parentNode);" />
</form>
<div id="ret2"></div>
</body>
<input type="button" value="close" onClick="google.script.host.close();" />
</html>
code.gs:
function launchSideBar() {
SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutputFromFile("ah1"));
}
function processForm(obj) {
console.log(obj);
const ss=SpreadsheetApp.getActive();
const sh=ss.getSheetByName('email');
sh.appendRow([obj.email,obj.subject,obj.message]);
return {number:obj.number,msg:"Email Sent"}
}
- 1 回答
- 0 关注
- 80 浏览
添加回答
举报