getText
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.
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
Tips
getText()
can also read the text on abutton()
ortextLabel()
.
Found a bug in the documentation? Let us know at support@code.org.