Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8236501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:09:16+00:00 2026-06-07T19:09:16+00:00

In a Google Apps Script, I have the following script: function doGet() { return

  • 0

In a Google Apps Script, I have the following script:

function doGet() {
  return HtmlService.createHtmlOutputFromFile('mypage');
}

function writeSomething() {
  return "<h1>hi people</h1>";
}

and the following html file:

<html>
  <a id="caller" href="#">update</a>
  <br>
  <div id="div">waiting...</div>
<script>
function go() {
  var a=google.script.run.writeSomething();
  document.getElementById("div").innerHTML=a;
}
document.getElementById('caller').onclick = go;
</script>
</html>

When I click on the “update” link, the div content changes from “waiting…” to “undefined”. I suppose that google.script.run cannot be called as a function.
So, how can I solve this trouble? (obviously, this is a toy example; I need a way to update the div content from the script and not from the html file)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:09:18+00:00Added an answer on June 7, 2026 at 7:09 pm

    The function writeSomething() is run asynchronously so it happens but doesn’t return the response as a local function would. (This is standard for JavaScript talking to a server). Instead, you need to specify a “callback” function which gets invoked when writeSomething() is finished.

    Here’s the corrected version of your HTML:

    <html>
      <a id="caller" href="#">update</a>
      <br>
      <div id="div">waiting...</div>
    <script>
    function callback(whatToWrite) {
      document.getElementById("div").innerHTML=whatToWrite;
    }
    function go() {
      google.script.run.withSuccessHandler(callback).writeSomething();
    }
    document.getElementById('caller').onclick = go;
    </script>
    </html>
    

    Or equivalently, you can specify the callback function inline:

    ...
    <script>    
    function go() {
      google.script.run.withSuccessHandler(function(whatToWrite) {
        document.getElementById("div").innerHTML=whatToWrite;
      }).writeSomething();
    }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 html documents inside my google apps script project (showHtml1, showHtml2). I
I have a Google Apps script which replaces placeholders in a copy of a
I have been playing around with Google Apps Script today and I am trying
I have read some of the basic Google Apps Script documentation/tutorials. I have not
I have now written a number of different functions in Google Apps Script that
I have built an object in Javascript on the Google Apps Script engine and
I've been looking at the Google Apps Script API documentation, and have not been
I have developed several general purpose script functions, for Google Spreadsheet apps. Currently I
In my javascript file I have the following: <script type=text/javascript src=https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js></script> <script type=text/javascript> $.ajax({
Please have a look at the following code: <HTML> <HEAD> <script src=//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js type=text/javascript></script> <SCRIPT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.