dropdown

Category:UI Controls

Creates a dropdown selection box on the screen displaying the options provided and referenced by the given id at default location (0,0).

Your apps will sometimes need to collect specific input from the user, instead of unrestricted input using textInput(). You can code an event handler that is triggered by various events in the dropdown box. Use getText() to get the option currently chosen in the dropdown.

Examples

Example Simple Form

Demonstrate UI element modification and query functions.

// Demonstrate UI element modification and query functions.
textLabel("yearLabel", "What is your year in school?");
dropdown("yearId", "Freshman", "Sophomore", "Junior", "Senior");
button("submitID", "Submit");
onEvent("submitID", "click", function(event) {
  console.log(getText("yearId"));
  setText("yearId", "Freshman");
});

//Get the user's mood.
dropdown("id", "happy", "sad");
onEvent("id", "change", function(event) {
  write(getText("id"));
});

Syntax

dropdown(id, option1, option2)

Parameters

Name Type Required? Description
id string The unique identifier for the dropdown box. The id is used for referencing the text input box in event handlers or other UI element modification functions. Must begin with a letter, contain no spaces, and may contain letters, digits, - and _.
option2 string The text displayed within the dropdown box.
option1 string The text displayed within the dropdown box.

Returns

No return value. Modifies screen only.

Tips

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