getText

Category:UI Controls

Gets the text from the specified screen element.

To capture data entered by the user, your apps will need to read data from textInput() or textArea screen elements. getText() is usually used in an onEvent() callback function, and returns a string that can be stored in a variable or used as a parameter in another function call.

Found a bug in the documentation? Let us know at documentation@code.org

Examples

Example Random Thoughts

Demonstrate reading and then clearing a textInput box.

// Demonstrate reading and then clearing a textInput box.
textInput("yourThought","");
onEvent("yourThought", "change", function(event) {
  write(getText("yourThought"));
  setText("yourThought","");
});

// Echo user input.
textInput("id", "Enter your name");
onEvent("id", "change", function(event) {
  write("Hi " + getText("id"));
});

Syntax

getText(id)

Parameters

Name Type Required? Description
id string The unique identifier for the screen element. Must begin with a letter, contain no spaces, and may contain letters, digits, - and _.

Returns

A string containing the contents of the screen element.

Tips

Found a bug in the documentation? Let us know at documentation@code.org