user1780546
user1780546

Reputation: 21

google script textarea or textbox want not give me text

How can I get text from textarea or textbox.

function myClickHandler() {
    var app = UiApp.getActiveApplication();
    var textbox = app.getElementById("TextBox1");
    var text = textbox.text;
    textbox.setText(text + "1");
    return app;
}

After run of this function is in my textarea: "undefined1".

On googledevelopers help page https://developers.google.com/apps-script/class_textbox is not getText method.

How can I get text from textbox?

Upvotes: 1

Views: 972

Answers (3)

Eric Koleda
Eric Koleda

Reputation: 12673

In order to pass a widget's value to a callback handler you must do two things:

  1. Assign a name to the widget when you create it.
    texbox.setName('foo');
  2. Add the widget as a callback element to the server handler you create.
    clickHandler.addCallbackElement(textbox);

If you've done that, then the value of the textbox will be passed in the event parameter of your callback function.

function myClickHandler(event) {
  var textboxValue = event.parameters['foo'];
  ...
}

Upvotes: 0

Harsha B N
Harsha B N

Reputation: 21

It's not textbox.text. It should be textbox.value.

function myClickHandler() {
    var app = UiApp.getActiveApplication();
    var textbox = app.getElementById("TextBox1");
    var text = textbox.value;
    textbox.setText(text + "1");
    return app;
}

Upvotes: 2

Praveen Vijayan
Praveen Vijayan

Reputation: 6761

Try this -

 var text = textbox.value;

Upvotes: 0

Related Questions