Home > OS >  Appscript run function onClick button from html template
Appscript run function onClick button from html template

Time:06-20

I'm tryng to run this function when button click from my html template.

    function sendTeacher(){
  Classroom.Invitations.create({
    "courseId": "ID",
    "userId": "E-mail",
    "role": "TEACHER"
      });

}`

I have tryed, onClick="", and others ways but seems i'm declaring the function API wrong. Could some one help me? i'm stuck on this.

<input type="button" onClick="sendTeacher()" value="Submit" /><br>`

Tryed to:

<script>
function clickBtn(){
var classEmails = document.getElementById("txt_Email").value;
var classID = document.getElementById("class").value;
document.getElementById("classEmail").innerHTML = classEmails   ": E-mail a ser inserido";
return Classroom.Invitations.create({
"courseId": classID,
"userId": classEmails,
"role": "TEACHER"
  });

};

Html file:

    <!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <?!= include('sideBarInsertStyle') ?>
    <?!= include('sideBarInsertSelect') ?>
  </head>
    <body>

        <input type="button" onClick="sendTeacher()" value="Submit" /><br>

  </body>
</html>

CodePudding user response:

Try to use "onclick" instead of "onClick"

according to w3shcool https://www.w3schools.com/jsref/event_onclick.asp it using lowercase not camel case

if the script are sparated file i suggest to use addeventlistener instead

CodePudding user response:

Try it this way:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <?!= include('sideBarInsertStyle') ?>
    <?!= include('sideBarInsertSelect') ?>
  </head>
    <body>
        <input type="button" onclick="google.script.run.sendTeacher();" value="Submit" />
  </body>
</html>

Either onclick or onClick will work

  • Related