0

The alert functions as expected, in that each click of the button increments the count variable. How would that variable be passed back as a parameter for doGet to handle server-side?

Contents of Code.js:

function doGet(e) {
  var params = JSON.stringify(e);
  Logger.log(params);
  var htmlOutput = HtmlService.createTemplateFromFile('index');
  htmlOutput.update = 'updated value is: ' + e.parameter['update'];
  htmlOutput.url = getUrl();
  return htmlOutput.evaluate();
}


function getUrl() {
  var url = ScriptApp.getService().getUrl();
  return url;
}

contents of index.html:

<!DOCTYPE html>
<html>

<head>
  <base target="_top">
</head>
<body>
    <button id="demoButton">Greetings for today</button>
    <script>
      var count = 0;
    document.getElementById("demoButton").addEventListener("click", function(){ alert("clicks   " + count);count++});
    </script>
   
</body>

</html>

How would something like this example:

<form action="<?= url ?>"  method="GET" >
<input type="text"  name="username" />
<input type="submit" name="Submit" /><br>
<span><?= username ?></span>
</form>

work with the above EventListener? This form has the advantage of sending parameters for doGet to handle.

No doubt many libraries would handle this very nicely; looking to use just "basic" JavaScript at the moment.

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • Please read carefully this recent question https://stackoverflow.com/q/74021359/1595451. Besides reload of the web app with url parameters it mentions the use of `google.script.run` and provides references. – Rubén Oct 11 '22 at 08:45

0 Answers0