I've spent 2 days trying to figure this out so any help is appreciated.

I was following this nice little video tutorial series and I wanted to try something basic before getting any further: get an html button to show a javascript alert using google apps script and their HTML Service component, but for the life of me, I can't understand why the alert is not triggered.

Here's my code


    <!DOCTYPE html>
              function showAlert() {
                alert("hello world");
              <label>Enter code</label>
              <input type="text" id="txtStudentID"/>
              <button id="btnSearch">Search</button>

and my code.gs

function doGet() {
  return HtmlService.createHtmlOutputFromFile('Index');

I also try it like google shows it here: but I still don't get the alert to trigger after the button is pressed:

<input type="button" value="Search"
          .withUserObject(this)" />

it's like anything that starts with "document.getElementByID..." within the script tags will simply not work

What am I missing? is this something not longer supported with GAPS? is there a different/proper way to get this to work?

thank you in advance.

1 Answers

Cooper On

Try putting addEvent into window.onload