Velo Code Help - Buttons with Multi State box

Question:
Hi, I am trying to use a multi state box with 4 buttons which changes the box’s state, however my code doesnt seem to be changing the box upon clicking a button. I have included my code below, any help would be appreciated alot :slight_smile:

$w.onReady(function () {
button1_click()
});

export function button1_click(event) {
$w(“#statebox8”).changeState(“State1”);
}

export function button2_click(event) {
$w(“#statebox8”).changeState(“State2”);
}

export function button3_click(event) {
$w(“#statebox8”).changeState(“State3”);
}

export function button4_click(event) {
$w(“#statebox8”).changeState(“State4”);
}

const blackColor = “#000000”;
const greyColor = “#C7C7C7”;

export function statebox8_change(event) {
const buttonNames = $w(“#columnStrip5”).children.filter((elem) => { return elem.id.includes(“button”) }).map((f) => { return f.id}); //[1,2,3,4]

buttonNames.map((name, index) => {

let button = $w(#${name}); // e.g. $w(“#button1”)
let length = index+1;
let state = “State”+length; // e.g. State1
//console.log(state);
if (event.target.currentState.id === state) {
button.style.backgroundColor = blackColor;
} else {
button.style.backgroundColor = greyColor;
}
})
}

Did you copy and paste this code from somewhere? Or did you actually use the code event’s panel to set the onClick event?

Hi,

I used the code from a tutorial video and made a few changes to it.

Many thanks,
Salim

Hi,

I managed to fix my code. Thank you for reaching out :slight_smile:

Best,
Salim