我有一个用于捕获电子邮件地址的输入文本框。提交后,我想将电子邮件地址添加到HTML后端的现有Google电子表格中。任何人都可以帮助我。谢谢提前。
代码 HTML:
<div class="form">
<div class="field_content">
<input class="field" type="text" id="email_id" />
<input class="submit" type="button" onclick="addEmail()"/>
</div>
</div>
的javascript:
<script type="text/javascript">
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
function addEmail(){
var email_id = $('#email_id').val();
if ((email_id != "") && (validateEmail(email_id))){
alert("valid");
//Here i want to save in Google Spreadsheet
}
else {
if(email_id == ""){
alert('Please enter Email ID');
return false;
}
alert('INvalid Email ID');
}
$('#email_id').val('');
}
</script>
答案 0 :(得分:0)
如果您使用的是Google Apps脚本,则必须使用:
google.script.run.gsFunctionNameInAppsScript()
Google Documentation - Client Side API - Apps Script
如果您不使用Apps脚本,则必须使用特定于服务器端语言的其他API。
<script>
function onSuccess(argReturnValue) {
if (argReturnValue === true) {
alert('The email was saved to the spreadsheet!');
};
};
function addEmail(){
. . . . Your existing code . . .
google.script.run.withSuccessHandler(onSuccess)
.addRowToSpreadsheet(email_id);
</script>
function addRowToSpreadsheet(argTheEmail) {
var thisSS = SpreadsheetApp.getActiveSpreadsheet();
var theSheet = thisSS.getSheetByName("Email_List");
theSheet.appendRow([argTheEmail]);
return true;
}