0

I am trying to use Google App Script for the first time and want to get data out of a textbox in on a button click (Into variable TC in the second function). I have tried to follow both from Google and online but it seems like all the functions hey use have been decommissioned. Can anyone give me some guidance on this, I don't have any experience with UIs and have been working at this project for several hours.

See simplified code below.

Thank you,

John

function doGet() {
  var app = UiApp.createApplication().setTitle('Richardson-Dushmann Calculator');

  var Temperature  = app.createTextBox().setName("Temperature");

  var button = app.createButton('Calculate').setId('Calculate');
  var handler = button.addClickHandler(app.createServerHandler("handlerFunction"));

  var inputGrid = app.createGrid(1, 3);
  var mypanel = app.createVerticalPanel();  

      inputGrid.setWidget(0, 0, app.createLabel('T = '));
      inputGrid.setWidget(0, 1, Temperature);
      inputGrid.setWidget(0, 2, app.createLabel(' \xB0C'));

      mypanel.add(inputGrid);
      mypanel.add(button);

  app.add(mypanel);
  return app;

}

function handlerFunction(e) {
  var app = UiApp.getActiveApplication();
  var TC = e.parameter.Temperature;

   return app;
 }

1 Answer 1

1

You have to tell the handler what widget value should be transmitted to the function.

You could add the textBox but it's a good practice to add the highest level parent widget in case you need other values later on.

Use handler.addCallBackElement(widget) to achieve that, documented here.

EDIT following comment :

full code

function doGet() {
  var app = UiApp.createApplication().setTitle('Richardson-Dushmann Calculator');

  var Temperature  = app.createTextBox().setName("Temperature");

  var inputGrid = app.createGrid(1, 3);
  var mypanel = app.createVerticalPanel();  

  var button = app.createButton('Calculate').setId('Calculate');
  var handler = button.addClickHandler(app.createServerHandler("handlerFunction").addCallbackElement(mypanel))


      inputGrid.setWidget(0, 0, app.createLabel('T = '));
      inputGrid.setWidget(0, 1, Temperature);
      inputGrid.setWidget(0, 2, app.createLabel(' \xB0C'));

      mypanel.add(inputGrid);
      mypanel.add(button);

  app.add(mypanel);
  return app;

}

function handlerFunction(e) {
  var app = UiApp.getActiveApplication();
  var TC = e.parameter.Temperature;

   return app.add(app.createLabel(e.parameter.Temperature));// add the returned value in the app to check it comes back in the handler
 }

test here

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

2 Comments

I tried doing this and it did not work. Even copy-pasting the code snippet under addCallbackElement in the Google documentation did not work.
see edit please... you probably forgot to change version

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.