[][src]Static p5_sys::global::createSelect

pub static createSelect: CreateSelectInternalType

Creates a dropdown menu select element in the DOM. It also helps to assign select-box methods to p5.Element when selecting existing select box.

  • .option(name, [value]) can be used to set options for the select after it is created.
  • .value() will return the currently selected option.
  • .selected() will return current dropdown element which is an instance of p5.Element
  • .selected(value) can be used to make given option selected by default when the page first loads.
  • .disable() marks whole of dropdown element as disabled.
  • .disable(value) marks given option as disabled

Examples

let sel;

function setup() {
  textAlign(CENTER);
  background(200);
  sel = createSelect();
  sel.position(10, 10);
  sel.option('pear');
  sel.option('kiwi');
  sel.option('grape');
  sel.selected('kiwi');
  sel.changed(mySelectEvent);
}

function mySelectEvent() {
  let item = sel.value();
  background(200);
  text('It is a ' + item + '!', 50, 50);
}
let sel;

function setup() {
  textAlign(CENTER);
  background(200);
  sel = createSelect();
  sel.position(10, 10);
  sel.option('oil');
  sel.option('milk');
  sel.option('bread');
  sel.disable('milk');
}

Overloads

multiple? true if dropdown should support multiple selections


existing DOM select element