[英]Populate email input on HTML form from email value within google sheets cell
I've created a pop-up email dialog box within google's html editor as follows with the input for email as follows: 我已经在Google的html编辑器中创建了一个弹出电子邮件对话框,如下所示,电子邮件的输入如下:
<input type="email" name="email" class="form-control" id="mail" aria-describedby="emailHelp" value="">
In my .gs file I'm storing the value of my cell containing the email address I want to use as follows: 在我的.gs文件中,我存储包含要使用的电子邮件地址的单元格的值,如下所示:
function getEmail()
{
var s=SpreadsheetApp.getActive().getSheetByName("Template");
var row=15;
var column=3;
var contactAddress=Utilities.formatString('%s',s.getRange(row, column).getValue());
Logger.log(contactAddress);
}
This works fine and is capturing the email address correctly and logging it. 这可以正常工作,并且可以正确捕获电子邮件地址并将其记录下来。 I now need to change the 'value' of my email input so that it populates with this address when the diolog opens.
现在,我需要更改电子邮件输入的“值”,以便在打开二元日志时使用此地址填充该电子邮件。 So I have the following in my HTML file:
因此,我的HTML文件中包含以下内容:
window.onload = function (contactAddress)
{
document.getElementById('mail').value=contactAddress;
}
However, this is resulting in '[object Event]' being populated. 但是,这将导致填充“ [对象事件]”。 I feel I'm close here but can't quite get it over the line!!!!
我觉得我在这里很近,但不能完全摆脱!
UPDATE: 更新:
So I added this to my .gs: 所以我将其添加到我的.gs:
function showDialog() {
var html = HtmlService.createHtmlOutputFromFile('emailTemplate')
.setWidth(800)
.setHeight(500);
html.myvar = new getEmail();
html.evaluate().getContent();
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog(html, ' ');
}
However, when I run the script I get an error stating Object does not allow properties to be added or changed. 但是,当我运行脚本时,出现错误消息,指出对象不允许添加或更改属性。
Edit: Original answer deleted. 编辑:原始答案已删除。
So here is my answer to your problem. 所以这是我对您问题的回答。 Tested it out, and it works.
测试了一下,就可以了。
My HTML page is set up like this just to test it: 我的HTML页面设置如下:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function onSuccess(contact) {
//var contactAddress = google.script.run.getEmail();
document.getElementById('mail').value=contact;
}
google.script.run.withSuccessHandler(onSuccess).getEmail();
</script>
</head>
<body>
<input type="email" name="email" class="form-control" id="mail" aria-describedby="emailHelp" value="">
</body>
</html>
My .gs file contains 我的.gs文件包含
function getEmail()
{
var s=SpreadsheetApp.getActive().getSheetByName("Sheet1");
var row=1;
var column=3;
var contactAddress=Utilities.formatString('%s',s.getRange(row, column).getValue());
Logger.log(contactAddress);
return contactAddress;
}
The only real difference is that I added a return statement (and changed the row from 15 to 1 for my test). 唯一真正的区别是,我添加了一个return语句(并将测试的行从15更改为1)。
Seems the main problem was how you were calling the function on the HTML page. 似乎主要问题是您如何在HTML页面上调用该函数。 It needed a
google.script.run.withSuccessHandler()
call instead of a window.onload = function()
call. 它需要
google.script.run.withSuccessHandler()
调用,而不是window.onload = function()
调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.