0

I tried this tutorial, but it was not written for v8-- and the logger and javascript parameter passing between html and the script doesn't work. https://www.youtube.com/watch?v=RRQvySxaCW0 I learned how to use the older rhino version of google apps script, but am unable to get variables to pass from HTML to the script.

In the second part, they give an example of using javascript to pass the username to the script. Inside the HTML file after the body tag:

<h1>Hello</h1>
<label>Name</label><input type="text" id="username">
<button id="btn">Run It!</button>
<script>
document.getElementById("btn").addEventListener("click",doStuff);

function doStuff(){
var usname = document.getElementById("username").value;
google.script.run.userClicked(usname);
document.getElementById("username").value="";
}
</script>

and in the script I have:

function userClicked(uname){
  Logger.log(uname + " clicked");
}

But I don't receive any data in uname. It says "undefined clicked" in the log. Any suggestions to get this to run?

4
  • It's very likely that your HTML file hasn't a tag with id equal to "username" or if this tag exists that the value attribute is empty. Add the code of your HTML file so we could tell you something more specific. Commented Mar 31, 2020 at 19:05
  • okay, I updated the script code inside the HTML file. Thanks for you help @Rubén
    – anjchang
    Commented Apr 1, 2020 at 21:27
  • 1
    @anjchang So, all OK now?
    – Tedinoz
    Commented Apr 13, 2022 at 0:59
  • 1
    Yes, thank you! @Tedinoz. I used these steps webapps.stackexchange.com/questions/140908/… and then the problem went away.
    – anjchang
    Commented May 5, 2022 at 0:22

0

Browse other questions tagged or ask your own question.