Addressing TextButton Label Text via Javascript?

Andrew's icon

I'm trying to change many textbuttons' text with a simple javascript, but I can't figure out how to address the button's text. Is this possible or do I have to use a JSUI object to make the buttons first.

I'm attaching a small example.
Thanks!

4672.buttonText.js
js
Ben Bracken's icon

Hi Whale Bone,

One way of doing it is to just send a message to the object, using 'myobject.message()':

inlets = 1;
outlets = 1;
autowatch = 1;

p = this.patcher;
var textvalues = ["Off","On"];

function ToggleButton(a) {
    if (a==0) { Setting=0; } else { Setting=1; }
    var b=p.getnamed("buttonOnOff");
    b.message("text", textvalues[a]);

}

Andrew's icon

Thanks so much! I had tried that, but I realize now that I'd forgotten to include the "text" argument. D'oh! So simple.
Thanks again.

Ben Bracken's icon

Alternately, you can set the attr like this:

b.text(textvalues[a]);

-Ben

Andrew's icon

Thanks again. That's very helpful.