Switch

Quick question, is it possible to create a button that when pressed displays a textbox with “ON” and then when pressed again displays a textbox with “OFF”, and continues with “ON”, “OFF” everytime it is clicked.
The ON and OFF textbox can be the same textbox or two different textboxes, but I would prefer to have two separate textboxes.

Thanks

Create a button in your page and change the id to something more meaningful, for example ‘switch’ like i did here below. then in its text set it to “On” as its initial state.

then in your page drop the following code:

$w.onReady(function () {
$w(‘#switch’).onClick(event => {
if($w(‘#switch’).label === ‘On’){
$w(‘#switch’).label = ‘Off’;
}else{
$w(‘#switch’).label = ‘On’;
}
});
});

you can of course play with additional properties of the button to suit your design

Thanks this works great!