This has been driving me crazy- I can't figure out why it wont work!
I have two files: myPage.html and myCode.gs in google scripts. I have deployed the html file as a web app, and I want the onclick event for the submit button to trigger the emailTech function from the myCode.gs file but it won't work! When I run the function straight from the file, it works fine.
I've done a few hours of research and tried to add <script type="text/javascript" src="myCode.gs"></script>
but that causes an error when I refresh the web app. I have tried calling the function in the onClick event as onClick= "google.script.run.emailTech()"
and onClick= "emailTech()"
but neither work. I have also tried loading the emailTech function into the script tag in the header, but that didn't work either! What am I missing? Please help!
myPage.html file:
<script type="text/javascript"></script>
<body>
<input type="submit" onclick="emailTech();" value="Submit" />
</body>
myCode.gs file:
function doGet() {
return HtmlService.createHtmlOutputFromFile('myPage');
}
function emailTech(){
Logger.log("is this firing?");
var message = "This is the email message";
MailApp.sendEmail("[email protected]", "This is the subject", message );
}
onclick
events.<input type='button' value='Never Clicked' onclick='google.script.run.withSuccessHandler(updateButton).withUserObject(this).getCurrentDate()'>
I believe you cant call a Gs script like you would do with a JS. – Jacobvdb May 9 at 0:58