How do I enable/disable a selection box?

Is this possible?

I know that I can disable options in a selection box via .disable(option) but I’d like to be able to enable/disable the box itself.

1 Like

Yes, it’s possible. One cool aspect of p5.js is that it builds upon web technologies. Everything is just HTML, CSS, and JavaScript. Your select box is a HTML <select> element. To disable it, you have to set the disabled attribute on that element. Like this:

  mySelect = createSelect();
  mySelect.attribute('disabled', true);
3 Likes

I think this .attribute function is the most useful thing I have learned about p5.js and somehow it’s the first time that I’m learning of it. It’s suddenly become clear to me how powerful this library really is.

For some reason I’m unable to change the disabled attribute more than once.
I can disable the select box but cannot re-enable it.

mySelect.attribute(‘disabled’,false);
doesn’t work for some reason.

What am I doing wrong here?

https://editor.p5js.org/Bassam/sketches/PxWpubFb6

2 Likes