checkbox

Category:UI Controls

Creates a checkbox on the screen with the initial checked boolean value and referenced by the given id at default location (0,0).

Some apps require the user to check a box if they agree with something, like an app privacy statement.

Examples

Example: Checkbox Click Event

Retrieve and display a checkbox value.

// Retrieve and display a checkbox value.
checkbox("agreeBox", false);
textLabel("agreeLabel","I agree to the above privacy statement.","agreeBox");

textLabel("response1","Response: ");
textLabel("response2","");
onEvent("agreeBox", "click", function() {
  setText("response2",getChecked("agreeBox"));
});

// Create a basic privacy statement checkbox.
checkbox("agreeBox", false);
textLabel("agreeLabel","I agree to the above privacy statement.","agreeBox");

Syntax

checkbox(id, checked)

Parameters

NameTypeRequired?Description
id string The unique identifier for the screen element. Must begin with a letter, contain no spaces, and may contain letters, digits, - and _. |
checked boolean Whether the checkbox is initially checked.

Returns

No return value. Modifies screen only.

Tips

  • If there is another UI element at location (0,0) the checkbox is placed at the next available position to the right or below.
  • There are various UI element modification functions available: setText(), showElement(), hideElement(), deleteElement(), setPosition(), setSize().
  • There are various UI element query functions available: getText(), getXPosition(), getYPosition().
  • Buttons can also be created and initi
  • Checkboxes usually have an associated textLabel.
  • If you are asking the user something with multiple responses, consider using grouped radio buttons instead.
  • The checkbox can also be created in design mode.

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