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>
2
  • I'm not sure what you're trying to do but here's an example of an html form:stackoverflow.com/a/60365261/7215091 here's another : stackoverflow.com/a/59585277/7215091 Commented Apr 5, 2021 at 4: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 Commented Apr 7, 2021 at 13:32

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.