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
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")); });
getText(id)
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 _. |
A string containing the contents of the screen element.
getText()
can also read the text on a button()
or textLabel()
.Found a bug in the documentation? Let us know at documentation@code.org