1

this my sample project in app script.i am beginer in making projects in webapp. in this project, I could run a button click event and I could not enter data in input control by clicking the button. I will be thankful if anyone helps me.

code.js:

    function doGet() {
      return HtmlService.createHtmlOutputFromFile('index');
    }
    function typesomething(x) {
      Logger.log(x+' to call!');
    }
    function dosomething() {
      Logger.log('succefullly executed'); 
    }

index.html:

     <!DOCTYPE html>
      <html>
       <head>
        <base target="_top">
    
         <script>
    
           google.script.run.doSomething();
        
           var txtname=document.getelementById("txt1");

           function getdata() {
             google.script.run.typesomething("MURTY LIKES TO  ");
             document.getelementById("txt1").value="hello world";
           }
        
         </script>
       </head>
       <body>
         <input type="button" value="ACCEPT" onClick="getdata()"/>
         <input type="text" placeholder="Enter Name."  id="txt1"/>
       </body>
  </html>
Michele Pisani
  • 13,567
  • 3
  • 25
  • 42
  • I'm not sure what you're trying to do but here's an example of an html form:https://stackoverflow.com/a/60365261/7215091 here's another : https://stackoverflow.com/a/59585277/7215091 – Cooper Apr 05 '21 at 04:28
  • thank you, Mr. Michele Pisani my problem is solved. But when I try to execute google.script.run.userFunction from HTML page, the function is not executed.to execute A function written in the code.js file, I want to run it from an HTML file using google.script.run. Then Shall I need to include any libraries – MURTY PHYSICS VIDEOS Apr 07 '21 at 13:32

1 Answers1

0

There are a couple of typos

<!DOCTYPE html>
<html>

<head>
    <base target="_top">

    <script>
        google.script.run.dosomething(); // Was doSomething, whereas in your script it is dosomething
        
           var txtname=document.getElementById("txt1"); // not getelement

           function getdata() {
             google.script.run.typesomething("MURTY LIKES TO  ");
             document.getElementById("txt1").value="hello world"; // not getelement
           }
        
    </script>
</head>

<body>
    <input type="button" value="ACCEPT" onClick="getdata()"/>
    <input type="text" placeholder="Enter Name."  id="txt1"/>
       </body>

</html>

Watch your capitals!

enter image description here

iansedano
  • 6,169
  • 2
  • 12
  • 24