rearThing
rearThing

Reputation: 632

Calling function inside an onclick using Apps Script

I suspect there is some sanitation process in the apps script server that prevents the onclick command to pass a value to the function. Is there a work around this? Here is what I've got:

    function func() {

  var template = HtmlService.createHtmlOutputFromFile('buttons');
  var content = (template.getContent());
  Logger.log(content)
  MailApp.sendEmail({
    to: '[email protected]',
    subject: 'subject',
    htmlBody: content

  });
}

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    Answer: <input type="text" id="myText" value="Try one button below">

<p>Try one of the answers below</p>

<button value='ttt' onclick="f1(this)">Try it</button>
<button value='ggg' onclick="f1(this)">Try it</button>
<button value='hhh' onclick="f1(this)">Try it</button>
<button value='eee' onclick="f1(this)">Try it</button>

<script>

function f1(obj){  
    if (obj.value == 'ttt'){
    document.getElementById("myText").value = 'Correct!';
    }
    else{
    document.getElementById("myText").value = 'Wrong answer..';
    }
}

</script>
  </body>
</html>

Upvotes: 0

Views: 239

Answers (1)

Wicket
Wicket

Reputation: 38210

AFAIK JavaScript is not allowed on HTML content for email messages by modern email clients / services as it represent a security risk.

Related

Upvotes: 1

Related Questions