pzero pzero - 18 days ago 8
HTML Question

Google Apps Script Textarea

I have the following basic code to attempt changing the value of the textarea element. Using standard HTML works fine; however, using Google Apps Script, it will not work. There will be more to the program which will include additional lines via \n so a standard input tag can't be used - this is just the basic piece in which I need to populate text within the element. Does anyone know if this is possible with GAS? Note, only wanting to use the HTML file, not pure GAS JavaScript.

<!DOCTYPE html>
<base target="_top">
<button id=calc>test</button>
<textarea id=t></textarea>
<script>
document.getElementById("calc").onclick=function(){
document.getElementById("t").value="test";
}
</script>

Answer

looks like you forgot to put "calc" and "t" inside quatation marks like this - "id_of_an_element"

When I used Visual Code to check if it works in pure HTML it fixed it, but in Google Apps Script it didn't

I tested the below code in Google Apps Script and it works, I hope it helps

<!DOCTYPE html>
<html lang="en">
<body>
<base target="_top">
<button id="calc">test</button>
<textarea id="t">my text area inital value</textarea>

<script>
  document.getElementById("calc").onclick=function(){
    document.getElementById("t").value="test";
  }
</script>

</body>
</html>