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 9269911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:14:26+00:00 2026-06-18T15:14:26+00:00

I have been playing with this small test code that – I admit –

  • 0

I have been playing with this small test code that – I admit – isn’t very useful but I noticed that the value returned in the callBackElement of the first handler is undefined when this handler is called for the first time.

I couldn’t figure out why… so I added a condition that solves the problem but I still would like to understand why this is working like that…

The script comes from a idea shown in this post earlier today, I commented the line that causes the error in the script below (it’s a bit long, sorry about that) and runs as a sort of timer/counter to illustrate the ability to fire a handler programmatically with checkBoxes.

If someone can explain why this condition is necessary ?

    var nn=0;
    //
    function doGet() {
      var app = UiApp.createApplication().setHeight('120').setWidth('200').setTitle('Timer/counter test');
      var Panel = app.createVerticalPanel()
      var label = app.createLabel('Initial display')
                     .setId('statusLabel')
      app.add(label);
      var counter = app.createTextBox().setName('counter').setId('counter').setValue('0')
      var handler1 = app.createServerHandler('loadData1').addCallbackElement(Panel);
      var handler2 = app.createServerHandler('loadData2').addCallbackElement(Panel);
      var chk1 = app.createCheckBox('test1').addValueChangeHandler(handler1).setVisible(true).setValue(true,true).setId('chk1');
      var chk2 = app.createCheckBox('test2').addValueChangeHandler(handler2).setVisible(true).setValue(false,false).setId('chk2');
      app.add(Panel.add(chk1).add(chk2).add(counter));
      SpreadsheetApp.getActive().show(app)
    }

    function loadData1(e) {
      var app = UiApp.getActiveApplication();
      var xx = e.parameter.counter
//*******************************************************
      if(xx){nn = Number(xx)}; // here is the question
    //  nn = Number(xx);       // if I use this line the first occurence = undefined
      nn++
      var cnt = app.getElementById('counter').setValue(nn)
      Utilities.sleep(500);
      var chk1 = app.getElementById('chk1').setValue(false,false)
      var chk2 = app.getElementById('chk2').setValue(true,true)
      var label = app.getElementById('statusLabel');
      label.setText("Handler 1 :-(");

      return app;
    }

    function loadData2(e) {
      var app = UiApp.getActiveApplication();
      var xx = Number(e.parameter.counter)
      xx++
      var cnt = app.getElementById('counter').setValue(xx)
      Utilities.sleep(500); 
      var chk1 = app.getElementById('chk1').setValue(true,true)
      var chk2 = app.getElementById('chk2').setValue(false,false)
      var label = app.getElementById('statusLabel');
      label.setText("Handler 2 ;-)");

      return app;
    }

The app looks like this:

enter image description here

and is testable here

EDIT : working solution is to fire the handler after adding the widgets to the panel (see Phil’s answer)
like this :

  var chk1 = app.createCheckBox('test1').addValueChangeHandler(handler1).setVisible(true).setId('chk1');
  var chk2 = app.createCheckBox('test2').addValueChangeHandler(handler2).setVisible(true).setId('chk2');
  app.add(Panel.add(chk1).add(chk2).add(counter));
  chk1.setValue(true,true);
  chk2.setValue(false,false);
  return app
  • 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-18T15:14:27+00:00Added an answer on June 18, 2026 at 3:14 pm

    The callback element which you specified for that handler (Panel) has no elements at the time that it is invoked. So you are essentially passing along a empty panel to that handler. So since chk1 hasn’t been added to the panel yet, its value isn’t added as a parameter to the handler.

    Put chk1.setValue(true,true) after the call to Panel.add(chk1).

    As seen in this example, the handler is queued when setValue(true,true) is called. This means that all the parameters that will be passed to the handler are gathered. It looks at the callback elements, reads their values, and then continues executing the doGet. After doGet finishes, the handler is executed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been playing with Python and I have this list that I need worked
I have been playing around with this preference activity code for most of the
I have been playing with the demo code from this msdn article by Jeffrey
I have been playing with this for a while, but the closest I have
I have been playing with this one for a few days now, and keep
Okay. Now I give up. I have been playing with this for hours. I
I am working on this site: beta.us.lt And I have been playing with firebug
I've been playing around with this for a couple of hours and have come
I have been playing with this for a day and cannot seem to get
I have been playing with this webbrowser control example I got it working and

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.