Isiah
Isiah

Reputation: 315

How do you pass HTML variables to google app scripts

I'm writing some to get the user's input in a text area and then to pass it to google app scripts to my main google script to email it on. I also tried to pass them through the project properties with no luck.

<!DOCTYPE html>
<html>

<head>
  <base target="_top">
</head>

<body>
  <p style="font-family:verdana;font-size:15px">Problem title</p>
  <input type="text" id="sDes"> <br><br>
  <p style="font-family:verdana;font-size:15px">Decription</p>
  <textarea style="resize: none;" rows="8" cols="63" id="lDes"></textarea>
  <button type="button" onclick="myFunction()">Send</button>
  <p id="demo"></p>
</body>
<script>
  function myFunction() {
    var a = document.getElementById("sDes").value;
    var b = document.getElementById("lDes").value;
  }
</script>

</html>

Upvotes: 0

Views: 882

Answers (1)

Cooper
Cooper

Reputation: 64140

Try this:

  1. run the openDialog() function after filling in serverfunctionname and htmlfilename.

Your html:

<!DOCTYPE html>
<html>

<head>
  <base target="_top">
</head>

<body>
  <p style="font-family:verdana;font-size:15px">Problem title</p>
  <input type="text" id="sDes"> <br><br>
  <p style="font-family:verdana;font-size:15px">Decription</p>
  <textarea style="resize: none;" rows="8" cols="63" id="lDes"></textarea>
  <button type="button" onclick="myFunction()">Send</button>
  <p id="demo"></p>
</body>
<script>
  function myFunction() {
    var a = document.getElementById("sDes").value;
    var b = document.getElementById("lDes").value;
    google.script.run.serverfunctionname(a,b);//modification
  }
</script>

</html>

GS:

function serverfunctioname(x,y) {
  SpreadsheetApp.getUi().alert('I received ' + x + ' and ' + y);
}


function openDialog() {
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutputFromFile('htmlfilename'), "My Dialog")
}

Upvotes: 2

Related Questions