I created a simple web app, and it is not working.
Code.gs:
function doGet() {//I think this works
var output = HtmlService.createTemplateFromFile('index').evaluate();
output.setSandboxMode(HtmlService.SandboxMode.IFRAME);
output.setTitle('email button');
return output;
}
function getContent(filename) {//might work
Logger.log('getContent()');
return HtmlService.createTemplateFromFile('javascriptCode').getRawContent();
}
index.html:
<!DOCTYPE html>
<html>
<body>
<form id="email_subscribe">
<input type="email" name="email" id="email" placeholder="Enter your email">
<input type="button" id="submitButton" value="Submit">
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" />
<?!= getContent("javascript") ?>
</body>
</html>
javascriptCode.html:
<script type="text/javascript">
$(document).ready(function() {
$("#submitButton").onclick(function() {
alert('thx for submitting');
});
});
</script>
When I run this webApp, the email and button fields load properly, and the logger logs 'getContent()'. However, nothing happens when I click the button. What am I doing wrong?
Thanks
There are quite few errors in your code.
code.gs
index.html
javascriptCode.html
A Simple HTML dialog example
I usually test these things as a dialog to get them working. It's works as a dialog and I've also included the doGet. I hope this helps. I didn't go exactly as you were going but I think this will help you move that way.
Code.gs:
webappdoesnotwork.html