Reputation: 697
This is driving me nuts. I've written a html page for my Google web app which has functions written in a .gs file. All I am trying to do is call the functions from the .gs file from the .html file. However, every method I have tried does not seem to work. I know my functions work because they work when I run just them. I am missing how to connect the .gs file to the .html file.
my .gs file looks something like this:
function doGet() {
return HtmlService.createHtmlOutputFromFile('index');
}
function test()
{
//getFormattedSpreadsheet("1xPDJJfCqWb2igug3NCFmJJ5nO49U6CK8mLwtaD727AY", "17qcsYh8M-cOwTg9K7sqqnKm0pGgEo6r7x1PguRf9Jk8", "Select School");
archiveSheet("1wTNing5LAOYHbscQ_DTktIxvWcyc6gw6ZNTvAJDtkTo", "1ugNP0Pp97tnRKHLHa50j-QKx-4ynCfg3zHxtJTayiVk");
}
I need the function to be called on a button click, I tried things like (or even without the google.script.run portion):
<button onclick="google.script.run(test())">Full</button>
but I can't get my button to actually call scripts. I've read you can call scripts to run by just putting them in function() tags as well, but I need this to run on click rather than on load. Perhaps I just don't understand the link between the .gs and .html file. They are seperate files, but within the same Google web app project.
Upvotes: 1
Views: 2994
Reputation: 31320
Your syntax is just slightly wrong. You have:
<button onclick="google.script.run(test())">Full</button>
Should be:
<button onclick="google.script.run.test()">Full</button>
You had a parenthesis where there should be a dot.
Google Documentation - Google Script Run API
Upvotes: 5