Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  50] [ 3]  / answers: 1 / hits: 34818  / 11 Years ago, wed, may 8, 2013, 12:00:00

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 );

}

More From » html

 Answers
261

EDIT: New answer - use google.script.run.



<script type=text/javascript></script>
<body>
<input type=button onclick=google.script.run.emailTech(); value=Submit />
</body>

[#78351] Tuesday, May 7, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mattieparisp

Total Points: 612
Total Questions: 109
Total Answers: 104

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
;