Sets the text for the specified screen element.
Your apps will sometimes need to change, or clear, the words displayed on screen elements. setText() can be used to update the text on a button, textInput, textLabel, or textArea.
Update the number on a button with every click.
// Update the number on a button with every click var count=0; button("clickCounter","0"); onEvent("clickCounter", "click", function(event) { count=count+1; setText("clickCounter", count); });
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",""); });
// Create a label for a screen title. textLabel("screenTitle",""); setText("screenTitle","My App");
setText(id, text)
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 _. | |
text | string | The text displayed within the screen element. |
No return value. Modifies screen only.
getText()
first if you need to save the data from a textInput()
to a variable.Found a bug in the documentation? Let us know at documentation@code.org